Jump to content

Search the Community

Showing results for tags 'stdinwrite'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Location


WWW


Interests

Found 10 results

  1. Hi, Background: i have a number of instances of the same application that I want to automate in parallel. Unfortunately, I cannot completely automate these instances in the background. So, from time to time these instances need to have the focus so that I can interact with the controls via “send” directly. Each of the application instances is controlled by a au3 complied script. Each script (called with a parameter) manages the automation of the respective application-instance. Each of the (complied) script (instances) is called by a (central) front end with a gui. The front end controls if the “focus” is available to do the “send” and “mouseclick” modifications. The central front end either allows a child to have the focus or prevents it to get the focus (in which case the child will wait and checks again). The code for the front end is included. Apologies for the lengthy explanation. #RequireAdmin #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <GUIEdit.au3> #include <ScrollBarConstants.au3> #include <Array.au3> Global Const $APF_ALLOWMULTILINE = 1 Global Const $APF_RIGHTALIGN = 6 Global Const $APF_RIGHTALIGNCOL = 2 Global Const $APF_RIGHTALIGNDATA = 4 Global Const $APF_PRINTROWNUM = 8 Global Const $APF_DEFAULT = $APF_PRINTROWNUM Global $PID[9], $FocusAvailable = True, $previousEditMsg Global $PID_waiting[0][2], $logfile $logfile = "D:\MultiInstance\Logfiles\FrontEnd.txt" If FileExists($logfile) Then FileDelete($logfile) #Region ### START Koda GUI section ### Form= $hGui_1 = GUICreate("Instanzenmanager", 493, 1226, 1807, 93) $grpInst1 = GUICtrlCreateGroup(" 1 ", 8, 8, 233, 121) $btnPause01 = GUICtrlCreateCheckbox("Pause", 16, 64, 50, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) $tbnStop01 = GUICtrlCreateCheckbox("Stop", 16, 96, 218, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) $btnMin01 = GUICtrlCreateCheckbox("Minimize", 72, 64, 66, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) $btnWdh01 = GUICtrlCreateCheckbox("Restore", 144, 64, 90, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) $btnStart01 = GUICtrlCreateCheckbox("Start", 16, 32, 218, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) GUICtrlSetBkColor(-1, 0x00FF00) GUICtrlCreateGroup("", -99, -99, 1, 1) $grpInst3 = GUICtrlCreateGroup(" 3 ", 8, 136, 233, 121) $btnPause03 = GUICtrlCreateCheckbox("Pause", 16, 192, 50, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) $tbnStop03 = GUICtrlCreateCheckbox("Stop", 16, 224, 218, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) $btnMin03 = GUICtrlCreateCheckbox("Minimize", 72, 192, 66, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) $btnWdh03 = GUICtrlCreateCheckbox("Restore", 144, 192, 90, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) $btnStart03 = GUICtrlCreateCheckbox("Start", 16, 160, 218, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) GUICtrlSetBkColor(-1, 0x00FF00) GUICtrlCreateGroup("", -99, -99, 1, 1) $grpInst2 = GUICtrlCreateGroup(" 2 ", 248, 8, 233, 121) $btnPause02 = GUICtrlCreateCheckbox("Pause", 256, 64, 50, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) $tbnStop02 = GUICtrlCreateCheckbox("Stop", 256, 96, 218, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) $btnMin02 = GUICtrlCreateCheckbox("Minimize", 312, 64, 66, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) $btnWdh02 = GUICtrlCreateCheckbox("Restore", 384, 64, 90, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) $btnStart02 = GUICtrlCreateCheckbox("Start", 256, 32, 218, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) GUICtrlSetBkColor(-1, 0x00FF00) GUICtrlCreateGroup("", -99, -99, 1, 1) $grpInst4 = GUICtrlCreateGroup(" 4 ", 248, 136, 233, 121) $btnPause04 = GUICtrlCreateCheckbox("Pause", 256, 192, 50, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) $tbnStop04 = GUICtrlCreateCheckbox("Stop", 256, 224, 218, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) $btnMin04 = GUICtrlCreateCheckbox("Minimize", 312, 192, 66, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) $btnWdh04 = GUICtrlCreateCheckbox("Restore", 384, 192, 90, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) $btnStart04 = GUICtrlCreateCheckbox("Start", 256, 160, 218, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) GUICtrlSetBkColor(-1, 0x00FF00) $Edit1 = GUICtrlCreateEdit("", 8, 720, 473, 497) $btnPauseAll = GUICtrlCreateCheckbox("Pause all", 8, 656, 474, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) $btnStopAll = GUICtrlCreateCheckbox("Stop all", 7, 688, 474, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 CheckGuiMsg() FileWrite($logfile, @HOUR & ":" & @MIN & ":" & @SEC & "> " & "CheckGuiMsg" & @CRLF) CheckClientMessages() FileWrite($logfile, @HOUR & ":" & @MIN & ":" & @SEC & "> " & "CheckClientMessages" & @CRLF) WEnd Func CheckGuiMsg() $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnStart01 AddTextToEdit("Starting Instance 1") $PID[0] = Run("D:\XVM05\Entwicklung_FilterTest_Multi_ToFileV001.exe 1", @ScriptDir, Default, 3) Case $btnStart02 AddTextToEdit("Starting Instance 2") $PID[1] = Run("D:\XVM05\Entwicklung_FilterTest_Multi_ToFileV001.exe 2", @ScriptDir, Default, 3) Case $btnStart03 AddTextToEdit("Starting Instance 3") $PID[2] = Run("D:\XVM05\Entwicklung_FilterTest_Multi_ToFileV001.exe 3", @ScriptDir, Default, 3) Case $btnStart04 AddTextToEdit("Starting Instance 4") $PID[3] = Run("D:\XVM05\Entwicklung_FilterTest_Multi_ToFileV001.exe 4", @ScriptDir, Default, 3) Case $btnPause01 AddTextToEdit("Send Pause to Instance 1") StdinWrite($PID[0], "Pause") Case $btnPause02 StdinWrite($PID[1], "Pause") Case $btnPause03 StdinWrite($PID[2], "Pause") Case $btnPause04 StdinWrite($PID[3], "Pause") Case $tbnStop01 StdinWrite($PID[0], "Stop") Case $tbnStop02 StdinWrite($PID[1], "Stop") Case $tbnStop03 StdinWrite($PID[2], "Stop") Case $tbnStop04 StdinWrite($PID[3], "Stop") Case $btnPauseAll AddTextToEdit(@CRLF & "************Pause All not yet implemented**************" & @CRLF) Case $btnStopAll AddTextToEdit(@CRLF & "************Stop All not yet implemented***************" & @CRLF) EndSwitch EndFunc ;==>CheckGuiMsg Func CheckClientMessages() For $i = 0 To 3 FileWrite($logfile, @HOUR & ":" & @MIN & ":" & @SEC & "> " & $i & @CRLF) Local $a = TimerInit() $p = $PID[$i] $streamRead = StdoutRead($p) If $streamRead <> "" Then Switch $streamRead Case StringInStr($streamRead, "Focus Needed") > 0 If $FocusAvailable Then $FocusAvailable = False StdinWrite($p, "Focus Granted") Else EndIf Case StringInStr($streamRead, "Release Focus") > 0 StdinWrite($p, "Release Focus Received") $FocusAvailable = True Case Else EndSwitch EndIf FileWrite($logfile, @HOUR & ":" & @MIN & ":" & @SEC & "> " & $i & " " & round(TimerDiff($a),2) & @CRLF) Next EndFunc ;==>CheckClientMessages Func AddTextToEdit($text) If $previousEditMsg <> $text Then $previousEditMsg = $text GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @YEAR & "." & @MON & "." & @MDAY & " - " & @HOUR & ":" & @MIN & ":" & @SEC & "> " & $text & @CRLF) _GUICtrlEdit_Scroll($Edit1, $SB_SCROLLCARET) EndIf EndFunc ;==>AddTextToEdit My issue now is that the mechanism with with StdoutRead and StdinWrite is not efficient at all. The more instances I start the slower it gets. This is not just a bit slower (like a fraction of a second), but to the degree that the front end is not responding at all any longer (with 3 instances handling). So my questions are: 1. Is there a flaw in my implementation with StdoutRead and StdinWrite? (note that all works fine with 1 and also (slower) with 2 instances running) but actually breaks down with 3 instances running. 2. Can I optimize the currently used implementation so that I can control 30+ instances? 3. What other implementation do you see suitable for this approach? a. I have already tried it with communication through files but observed that this is not sufficiently reliable with multiple instances. b. Is Named Pipes a more performant approach (I am a bit scared of the effort to learn and implement this) c. Any other method? Many thanks in advance -dubi
  2. Hello AutoIt community, I'm working on a project where I need to copy the bits of a file to a child process's StdIn stream. It's almost complete, but I have one final snag. The script uses DLLStructCreate to create a 64K buffer that holds the file's binary contents in memory. It iterates through the contents of the desired file in 64K segments, first pulling the bits into the buffer, then dumping the contents of the buffer out to the child process's StdIn stream. The child process then ultimately reconstitutes the file on a remote system. The child process does build the file in the target directory, but the problem is that the reconstituted file is always slightly larger than the original because it's always a multiple of 64K (when you look at the file properties, the size is always identical to the "size on disk" value). Storage consumption is not a concern since it's technically not occupying more space than the original, but file integrity is a concern. Not every file shows any signs of corruption when opening it, but some of the reconstituted files are completely useless because of this. I know that the problem lies within the last iteration of reading the source file; for example, if there are only 24K bits remaining to be read, that data gets stored in the DLLStruct along with 40K of zeros to fill the entire 64K buffer. When the file is reconstituted, this padding of zeroes is unfortunately also included. So my challenge is to try to figure out how to ignore these trailing zeroes while reading the final <64K bits of the file, or at least only send part of the contents of the DLLStruct buffer to StdIn. Does anyone know how to go about doing this? Thanks in advance, Jeemo
  3. OK so i'm trying to build a tool part of which adds a GUI to a command line tool. my tests seemed to work fine but when i ported my function into a GUI they break, the first time i invoke the commandline it returns nothing, then each subsequent time i press the button that calls to command line it ignores the current command and re-sends the last command. if i press the button a second time the command updates. IE let's say i have a command line app with a counter as one of the inputs. Press button to generate output -> "0" returned Press Button again with same paramaters -> "Hello world 1" returned Change counter to "2" press button -> "Hello world 1" returned press the button again -> "Hello world 2" returned THis was boggling my mind so i stripped out the GUI and took the function that was being called in the GUI and make it a hotkey call. now the exact same code that calls the commandline has different behavior Press hotkey to generate output -> "0" returned Press hotkey again with same paramaters -> "Hello world 1" returned Change counter to "2" press hotkey-> "Hello world 2" returned So a hotkey act's "normally" bot only after the initial "0" is returned. if I perform the function call for the command line before the hotkey while loop it functions properly the first time. : This seems like some sort of autoit bug but i have no idea how to work around it. : example code #include <Constants.au3> #include <array.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form=c:\users\datwater\documents\autoit\projects\otp tool\otp tool.kxf $Form1 = GUICreate("Form1", 392, 448, 191, 148) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") $Label1 = GUICtrlCreateLabel("seed", 23, 57, 35, 17) $txtSeed = GUICtrlCreateInput("", 66, 55, 213, 21) $btnRandomSeed = GUICtrlCreateButton("Create Seed", 287, 53, 74, 25) GUICtrlSetOnEvent(-1, "btnRandomSeedClick") $txtCounter = GUICtrlCreateInput("5", 72, 96, 71, 21) $txtLength = GUICtrlCreateInput("6", 223, 96, 48, 21) $Label2 = GUICtrlCreateLabel("Counter", 24, 99, 41, 17) $label3 = GUICtrlCreateLabel("Length", 173, 98, 37, 17) $txtOutput = GUICtrlCreateEdit("", 38, 213, 326, 201) $btnGen = GUICtrlCreateButton("Run Command", 149, 154, 80, 25) GUICtrlSetOnEvent(-1, "btnGenClick") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### local $key = "" local $length = 8 local $count = 5 Local $cmd = Run("cmd.exe", @ScriptDir, @SW_SHOWNORMAL, $STDIN_CHILD + $STDOUT_CHILD) While 1 Sleep(100) WEnd Func btnGenOTPClick() $length = GUICtrlRead($txtLength) $count = GUICtrlRead($txtCounter) $Seed = GUICtrlRead($txtSeed) $otp = runCommand($Seed,$length,$count) GUICtrlSetData($txtOutput,$otp & @CRLF, "|") EndFunc Func btnRandomSeedClick() GUICtrlSetData($txtKey,genKey(40)) EndFunc func runCommand($s,$l,$c) ;build the command $command = "oathgen.exe -c " & $c & " -l " & $l &" -s " & $s & "& @CRLF ConsoleWrite("COMMAND: " & $command & @CRLF) ; debug check ;send command to the console StdinWrite($cmd, $command) $line = "" ;loops and gathers all the command output While True $line &= StdoutRead($cmd) ConsoleWrite($line) ;debug If @error Then ExitLoop ;to exit the while loop we look for the blank command prompt, the trimming is needed to get a clean match. If StringRight($line,StringLen(@ScriptDir) + 1) = @ScriptDir & ">" Then ExitLoop Sleep(30) WEnd ;i do some parsing here of the output then return it , that all works fine EndFunc Basically where i'm calling StdinWrite($cmd, $command) i can see that $command is what i want it to be, but the first time it runs nothing is sent and the second time you press the button the command is correct but it actually sends the *old* command to standard in . This is only when running in a GUI though. if you lop out the runCommand function and run it just in a script it works as expected
  4. Hi all, Last day i was tried some inter process communication code but not succeeded, as it is a big deal for me. Then i tried with ConsoleWriteError function. It worked for me. Here is my code. I am seeking suggestions to improve. But my doubt is that; I can't understand the idea of StdinWrite function completely. This is what i think. Please correct me if i am wrong. 1. Make a child program for collect and send the data. 2. Make a parent program and run the child within it and receive data from the child program. So, i made the sample program with this scenario. But, when i looked StdinWrite function, it needs a process ID as a parameter. I thought that StdinWrite is used in the child program to send data to parent program. Am i right ?. My code Child program for collecting and sending data. Local $compName = @ComputerName ConsoleWriteError($compName) ExitParent program for receiving data #include <AutoItConstants.au3> Local $process = Run(@ScriptDir & "\stdWrite.exe","",Default, $STDERR_CHILD ) Local $Data While 1 $Data &= StderrRead($process) If $Data <> "" Then ExitLoop WEnd MsgBox(0, "Std Test Data", $Data)
  5. Question regarding StdinWrite and Stdoutread… Here’s my setup… I’m opening a powershell session using the AutoIT Run function with the $STDIN_CHILD and $STDOUT_CHILD optional flags. I’m then sending a command using the STDINWRITE function to connect to a remote server which is a long distance away and it takes a “long” time to return results. I’m then trying to read the STDOUT stream. After this there are other STDINWRITE statements that I need to make so the STREAM hasn’t closed at this point. My question is this…How do I know for sure when all the data has been returned from the remote server after my first STDINWRITE? Things I’ve tried and don’t work… Use a loop which waits for @error to be non-zero. This doesn’t work because as long as the STREAM is open then @error never is set to non-zero. Use a loop which waits for @extended to be 0. This doesn’t work because the remote server sends data back in bursts and I don’t know how much time will pass in-between bursts. The only thing that is somewhat reliable is utilizing very long sleep statements – like 5 minutes – which really slows down my script and doesn’t ensure success either. What I really need is a way to tell that control has been returned to the command prompt. What I mean by this is if you open a command prompt and issue the command DIR C:\ /s which lists all the files and folders on your C: drive you know you can’t issue any more commands until you get a blinking cursor at the command prompt again. How do I programatically know when I get a blinking cursor again? Sample code that isn’t 100% foolproof… This code uses the logic looking for an @error to be non-zero... #include <constants.au3> Dim $StrOutput $StrPowerShellPID = Run('C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  -command - ',@SystemDir, @SW_HIDE, $STDIN_CHILD + $STDERR_MERGED) StdinWrite($StrPowerShellPID, "Dir C:\" & @CRLF) ;this is just an example command ; I can't close the STDOUT stream at this point because I need to issue additional commands into the existing STDIN stream later in the script While 1 ;Wait for EOF as indicated by @error being non-zero     $StrOutput &= StdoutRead($StrPowerShellPID)     If @error <> 0 Then ExitLoop     sleep (500) WEnd Consolewrite($StrOutput)The above code doesn't work because @error will never be set to non-zero since the stream isn't closed. I can't close the stream because I need to issue additional commands into it. This code uses logic looking for an @extended value of 0 indicating no data was returned to the stream... #include <constants.au3> Dim $StrOutput $StrPowerShellPID = Run('C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command - ',@SystemDir, @SW_HIDE, $STDIN_CHILD + $STDERR_MERGED) StdinWrite($StrPowerShellPID, "Dir ""C:\program files\common files"" -recurse" & @CRLF) While 1 ;This loop detects when data starts to stream in and then exits the loop $StrOutput &= StdoutRead($StrPowerShellPID) If @extended > 0 Then ExitLoop sleep(1000) WEnd While 1 ;Now that data has begun to stream in I wait until I can't read any more data as indicated by 0 bytes read in the value of @extended $StrOutput &= StdoutRead($StrPowerShellPID) If @extended = 0 Then ExitLoop ;~ sleep (1000) ; this is the only way to get this specific sample to work but this won't work for me because I don't know the time in-between bursts of data coming into the STDIN stream WEnd ConsoleWrite($StrOutput) ;If you look at the output you'll see it's not complete because @extended was set to 0 during the second loopThe above code doesn't always work because if the remote server doesn't send any data for several seconds, then the StdoutRead thinks it's done reading when in reality it may not be.
  6. Hello , I am trying simulate user input in console apps, so far this is what I have tried: #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> Example() Func Example() Local $iPID = Run("test.bat", "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD) StdinWrite($iPID, "Banana") Local $sOutput = "" ; Store the output of StdoutRead to a variable. While 1 $sOutput &= StdoutRead($iPID) ; Read the Stdout stream of the PID returned by Run. If @error Then ; Exit the loop if the process closes or StdoutRead returns an error. ExitLoop EndIf WEnd MsgBox($MB_SYSTEMMODAL, "", "The output string is: " & @CRLF & $sOutput) EndFunc ;==>ExampleCode for test.bat: @echo off set /p var = "Input Var: " echo This is the var: %var% I can't write "Banana" when the the bat script prompts for input , I can't find any solution on the WWW for this... Thanks in Advance, TD
  7. Hey guys, I want to use Putty/Plink to connect on a remote computer via SSH because I need to execute a couple commands there. So I researched a couple days now and tried like 20 different ways to get this running but I'm still failing. Maybe a little description what my script should do: #Edit: Short version: I need to use StdoutRead to get the DOS command promt output MORE THAN ONCE! The first time is working, but I need to get this the whole time till I say stop ^^ I want to start Putty/Plink and connect via SSH on a remote computer AND I wanna check if there is anything wrong going on or not, because the next step would be the execution of an perl-script on the remote computer which is giving an output text while running. That means I'd like to be able to read out the Putty-Window/Plink-Console the whole time ... I'm actual just getting the text-output after connecting. Maybe a little example of what I'm expecting in some kind of mixed "AutoIt/Pseudo -Code": #include <Constants.au3> Local $iPID = Run('"C:\Program Files (x86)\Putty\putty.exe" -ssh root@HOST:22 -pw PASSWORD', @ScriptDir, @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD) Actual Putty-Window is popping up showing me: Using username "root". Linux COMPUTERNAME 2.6.31-22-generic-pae #63-Ubuntu SMP Wed Aug 18 23:57:18 UTC 2010 i686 To access official Ubuntu documentation, please visit: http://help.ubuntu.com/ System information as of Mo 13. Jan 15:01:50 CET 2014 System load: 0.0 Processes: 77 Usage of /: 47.5% of 9.15GB Users logged in: 1 Memory usage: 9% IP address for eth2: HOST Swap usage: 0% Graph this data and manage this system at https://landscape.canonical.com/ Last login: Mon Jan 13 14:58:43 2014 from XXX.X.X.XXX root@COMPUTERNAME:~# Now I'd like to do ControlSend($hWindow_Putty, '', '', 'perl -w /some/dir/script.pl{ENTER}') If I'd do this on my on with Putty I'd now see something like: Using username "root". Linux COMPUTERNAME 2.6.31-22-generic-pae #63-Ubuntu SMP Wed Aug 18 23:57:18 UTC 2010 i686 To access official Ubuntu documentation, please visit: http://help.ubuntu.com/ System information as of Mo 13. Jan 15:01:50 CET 2014 System load: 0.0 Processes: 77 Usage of /: 47.5% of 9.15GB Users logged in: 1 Memory usage: 9% IP address for eth2: HOST Swap usage: 0% Graph this data and manage this system at https://landscape.canonical.com/ Last login: Mon Jan 13 14:58:43 2014 from XXX.X.X.XXX root@COMPUTERNAME:~# perl -w some/dir/script.pl some text written by the script.pl some text written by the script.pl some text written by the script.pl root@COMPUTERNAME:~# And that's what my problem is. I need to be able to check this output of the script like "some text written by the script.pl" because I may not execute a following statement if this one didn't succeed. In my thoughts the first step should show me what I got in the first code-box above, and the second output should be perl -w some/dir/script.pl some text written by the script.pl some text written by the script.pl some text written by the script.pl root@COMPUTERNAME:~# but I dont get this working ... So I found many threads about Plink. I tried the whole thing with Plink... Local $sData = '' Local $iPID = Run('"C:\Program Files (x86)\Putty\plink.exe" -ssh root@HOST:22 -pw PASSWORD', @ScriptDir, @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD) While True $sData &= StdoutRead($iPID) If @error Then ExitLoop Sleep(25) WEnd ConsoleWrite("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & @CR & _ $sData & @CR & _ "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & @CR) I'm getting the following output: Linux COMPUTERNAME 2.6.31-22-generic-pae #63-Ubuntu SMP Wed Aug 18 23:57:18 UTC 2010 i686 To access official Ubuntu documentation, please visit: http://help.ubuntu.com/ System information as of Mo 13. Jan 15:35:53 CET 2014 System load: 0.0 Processes: 77 Usage of /: 47.5% of 9.15GB Users logged in: 1 Memory usage: 9% IP address for eth2: HOST Swap usage: 0% Graph this data and manage this system at https://landscape.canonical.com/ Last login: Mon Jan 13 15:23:36 2014 from MY_IP_ADRESS In comparison to the Putty window-output I'm missing here the root@COMPUTERNAME:~# line ... anyway, I don't get this Plink thing doing more then just connecting ... no more executions I'm getting done ... I also tried something like: #RequireAdmin #include <Constants.au3> Local $sData = '' Local $iPID = ShellExecute(@ComSpec, '"C:\Program Files (x86)\Putty\plink.exe" -ssh root@HOST:22 -pw PASSWORD', @ScriptDir, '', @SW_SHOW) Local $hWindow = WinWait('Administrator: C:\Windows\system32\cmd.exe', '', 5) ConsoleWrite("WinWait: " & $hWindow & @CR) If $hWindow = 0 Then Exit ConsoleWrite("WinActivate: " & WinActivate('Administrator: C:\Windows\system32\cmd.exe') & @CR) ConsoleWrite("WinActive: " & WinActive('Administrator: C:\Windows\system32\cmd.exe') & @CR) Sleep(1000) ConsoleWrite(ControlSend('Administrator: C:\Windows\system32\cmd.exe', '', '', '"C:\Program Files (x86)\Putty\plink.exe" -ssh root@HOST:22 -pw PASSWORD{ENTER}') & @CR) ;StdinWrite($iPID, '"C:\Program Files (x86)\Putty\plink.exe" -ssh root@HOST:22 -pw PASSWORD' & @CRLF) ;StdinWrite($iPID) While True $sData &= StdoutRead($iPID) If @error Then ExitLoop Sleep(25) WEnd ConsoleWrite("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & @CR & _ $sData & @CR & _ "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & @CR) but unfortunately I dont get anything out of it ... Maybe a last more example ... I found this on Stackoverflow (http://stackoverflow.com/questions/19206834/command-prompt-and-autoit-stdinwrite) Thats my code after reading that article: #include <Constants.au3> Local $data Local $pid = Run("C:\Windows\system32\cmd.exe",@SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD) StdinWrite($pid,"cd C:\users\username") StdinWrite($pid,@CRLF) ;~ StdinWrite($pid) Sleep(2000) $data &= StdoutRead($pid) ConsoleWrite("Debug:" & $data & @LF) $data = '' StdinWrite($pid,"cd C:\Program Files (x86)") StdinWrite($pid,@CRLF) StdinWrite($pid) $data &= StdoutRead($pid) ConsoleWrite("Debug:" & $data & @LF) but the second output still empty... Can you guys please help me out? Thanks in advice. Regards.
  8. I have been wracking my brains today trying to figure out how to send a control character to a DOS command I initiate within a script. I am doing this little project to eventually add a GUI to some older DOS based apps still in use. (Not everyone appreciates the fine art of command line execution I guess ) Anywho, to test my scripting and what I was able to dig up, I came up with the following. (Yes, I know AutoIT has a ping function, DOS ping was what I came up with to test sending commands to, it is not the final program) #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <process.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### $Main = GUICreate("Ping Now", 547, 62, 192, 124) GUISetFont(10, 400, 0, "MS Sans Serif") GUISetOnEvent($GUI_EVENT_CLOSE, "MainClose") GUISetOnEvent($GUI_EVENT_MINIMIZE, "MainMinimize") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "MainMaximize") GUISetOnEvent($GUI_EVENT_RESTORE, "MainRestore") $tbPingURL = GUICtrlCreateInput("", 16, 16, 425, 24) GUICtrlSetOnEvent($tbPingURL, "tbPingURLChange") $btnPingStart = GUICtrlCreateButton("Ping Now", 456, 16, 75, 25) GUICtrlSetOnEvent($btnPingStart, "btnPingStartClick") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $srPID While 1 Sleep(100) WEnd Func btnPingStartClick() Local $sURL = GUICtrlRead($tbpingURL),$stdOutLine MsgBox(0,"Ping URL","Reading URL: "&$sURL) ;ignored as I got tired of typing $srPID = Run(@ComSpec&" /c "&"ping -t yahoo.com","",@SW_HIDE,$STDIN_CHILD + $STDOUT_CHILD) ConsoleWrite("Running with PID: "&$srPID&@CRLF) Sleep(1000) EndFunc Func MainClose() ;ControlSend(@ComSpec,"","",Chr(3),1) ;ConsoleWrite(_ProcessGetName($srPID)) $charout=StdinWrite($srPID,Chr(3)) ConsoleWrite($charout&" - "&@error&@CRLF) StdinWrite($srPID) ;ProcessWait($srPID) ProcessWaitClose($srPID) Exit EndFunc Func MainMaximize() EndFunc Func MainMinimize() EndFunc Func MainRestore() EndFunc Func tbPingURLChange() EndFunc When I close the resulting window, I am expecting a CTRL+c to be sent to the running Ping command. Instead, I get a result code back implying that the command was send but nothing happens after that. Ping continues to run in the background till I end its process through Task Manager. When I end the process, the script closes, provided I attempt to close the GUI window (Func MainClose()). If I do not try to close the GUI first and end the ping process through task manager, I get a '0' as the result code for StdInWrite. The PID returned is NOT that of the child process initiated by the Run command but that of the cmd.exe that is started to run the Ping command within. Leaving off the @comspec portion of the Run statement makes no difference, the ping continues to run till ended. Any suggestions? I noted that other queries about sending control keys to DOS commands have been posted in the past but I didn't really pick up on a solution.
  9. #RequireAdmin #include <Constants.au3> ; Demonstrates the use of StdinWrite() Local $foo = Run("cmd", @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD) ; Write string to be sorted to child sort.exe's STDIN $local = "localhost" StdinWrite($foo, $local) ; Calling with no 2nd arg closes stream StdinWrite($foo) ; Read from child's STDOUT and show Local $data While True $data &= StdoutRead($foo) If @error Then ExitLoop Sleep(25) WEnd MsgBox(0, "Debug", $data) There must be something I am missing because If I use the example in autoit for StdinWrite() it works fine but when I try to write something it keeps displays "More?" as the response. Why is this happening. Yes I search around the forums and the help file but found nothing. If I did miss something please point it out.
  10. What I am attempting to do is use AutoIt to read and write to the minecraft (bukkit) console The console itself comes up as a cmd window when you start the jar with a .bat file. So far I have been able to read FROM StdoutRead, but I have had less success writing TO the console and getting any kind of response. Here is the server, example .bat file, and the following script: #include <GuiEdit.au3> OnAutoItExitRegister("close") hotkeyset("{ENTER}","enter") $GUI = GUICreate("MC Console Wrapper", 514, 251, 192, 124) $Edit = GUICtrlCreateEdit("", 8, 8, 497, 209, 2101312) $Input = GUICtrlCreateInput("", 8, 224, 497, 21) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $temp = FileFindFirstFile("*.bat") $server = run(FileFindNextFile($TEMP),@WorkingDir,default,0x7) ConsoleWrite($server&@CRLF) While 1 $temp = "" $temp = StderrRead($server) if @extended > 2 then GUICtrlSetData($Edit,guictrlread($Edit)&@CRLF&$temp) _GUICtrlEdit_Scroll($Edit, 7) EndIf $temp = StdoutRead($server) if @extended > 2 then GUICtrlSetData($Edit,guictrlread($Edit)&@CRLF&$temp) _GUICtrlEdit_Scroll($Edit, 7) EndIf $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit EndSwitch WEnd func enter() if WinActive($gui) Then If guictrlread($Input) <> "" Then StdinWrite($server,guictrlread($Input)) consolewrite(@error&@CRLF) GUICtrlSetData($Input,"") EndIf Else hotkeyset("{ENTER}") send("{enter}") hotkeyset("{ENTER}","enter") EndIf EndFunc func close() Do ProcessClose("java.exe") until ProcessExists("java.exe") = 0 EndFuncAny help would be appreciated
×
×
  • Create New...