skroo Posted July 25, 2014 Share Posted July 25, 2014 For example I launch php scripts. They read stdin and execute some actions depending on my input. For console apps I use RunWait, but it fails when child proccess tries to read stdin. I've read a lot of threads. Many users suggest launch via Run() with infinite loops reading stdout. But when I launch php scripts I don't know what messages I have to catch. I found this thread: '?do=embed' frameborder='0' data-embedContent>> But answer there is unclear for me. Summary: I want to interact with child proccesses with prompts the same way if they were launched directly from console w/o (parent) autoit script. Is it possible? Link to comment Share on other sites More sharing options...
skroo Posted July 25, 2014 Author Share Posted July 25, 2014 Anyone? Link to comment Share on other sites More sharing options...
JohnOne Posted July 25, 2014 Share Posted July 25, 2014 Your post is difficult to understand just exactly what it is you are attempting. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
skroo Posted July 25, 2014 Author Share Posted July 25, 2014 (edited) Well. 3rd-party console script.php: <?php fwrite(STDOUT, "Enter string: "); $input = fgets(STDIN, ...); if ($input === 'yes') { do_action(); } My autoit console app: RunWait('php script.php', ...) When I launch my app then php's script writes prompt text "Enter string: ", but automatically skips stdin - i can't type "yes". Edited July 25, 2014 by skroo Link to comment Share on other sites More sharing options...
Muzaiyan Posted July 25, 2014 Share Posted July 25, 2014 tell me if i am reight Use Stdinout to get the text use this to send a text i am using CLS (the clear screen on DOS) Run("cmd.exe") ; php progrem Sleep(1000) ControlSend("[CLASS:ConsoleWindowClass]","","","cls{ENTER}type code here") but i hope this will help you read this also Window Titles and Text (Advanced) if you know the title and INSTANCE Link to comment Share on other sites More sharing options...
skroo Posted July 25, 2014 Author Share Posted July 25, 2014 (edited) I know it's possible to send something somewhere. But I'd like to avoid this method. Sending "yes" is just an example. And first of all I need enter answers manually but not send them. Scripts are 3rd-party and I don't know all possible answers I have to enter. Again: I want the simplest solution as possible. When I open cmd.exe and there run my php script.php I get the expected result - stdin works, I can type. I want the same behavior when launch this script from autoit app. Edited July 25, 2014 by skroo Link to comment Share on other sites More sharing options...
JohnOne Posted July 25, 2014 Share Posted July 25, 2014 I believe you need to specifically add the specific flag to Run.Such as $STDIN_CHILD etc... AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
skroo Posted July 25, 2014 Author Share Posted July 25, 2014 I believe you need to specifically add the specific flag to Run. Such as $STDIN_CHILD etc... I've tried this. Run is non-blocking, so in this case I need an infinite loop within read stdout and somehow wait for stdin reading, right? I'm a little surprised that this simple task needs these tricks Link to comment Share on other sites More sharing options...
JohnOne Posted July 25, 2014 Share Posted July 25, 2014 Have you tried compiling as a cui app? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
skroo Posted July 25, 2014 Author Share Posted July 25, 2014 Have you tried compiling as a cui app? I'm not sure, but I compile app with /console command line option Link to comment Share on other sites More sharing options...
JohnOne Posted July 26, 2014 Share Posted July 26, 2014 Tried runwait with $RUN_CREATE_NEW_CONSOLE flag.In fact I think you should show all what you have tried. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
skroo Posted July 26, 2014 Author Share Posted July 26, 2014 I believe you need to specifically add the specific flag to Run. Such as $STDIN_CHILD etc... I'm trying STDIN again. As I understand in this case child's stdout/stderr go directly into parent's streams. And I have to get ConsoleRead() input and send it to child's stdin via StdinWrite(). But how can I determine that child stopped outputing and waits for input from keyboard? Link to comment Share on other sites More sharing options...
skroo Posted July 26, 2014 Author Share Posted July 26, 2014 (edited) In fact I think you should show all what you have tried. What I have now: Local $ApplicationPid = Run($appCmdLine, $ApplicationWorkingDir, $showFlag, $STDIN_CHILD + $STDOUT_CHILD) Local $prompt Local $answer Local $bytes Local $errorCode While ProcessExists($ApplicationPid) While 1 $prompt = StdoutRead($ApplicationPid) $bytes = @extended $errorCode = @error If $errorCode Or $bytes Then ExitLoop Sleep(1) WEnd ConsoleWrite($prompt) While 1 $answer &= ConsoleRead() $bytes = @extended $errorCode = @error If $bytes > 0 And StringInStr($answer, @CRLF) Then ExitLoop If $errorCode Then ExitLoop Sleep(1) WEnd If $answer Then StdinWrite($ApplicationPid, $answer) EndIf WEnd Almost what I need, but skips StdoutRead() block if child script works but does not output PHP script: <?php fwrite(STDOUT, 'Type "yes" to continue: '); $answer = fgets(STDIN, 4096); if (strtolower(trim($answer)) !== 'yes') { fwrite(STDOUT, 'Aborted'); exit; } sleep(1); fwrite(STDOUT, '1'); sleep(1); fwrite(STDOUT, '2'); fwrite(STDOUT, PHP_EOL . 'Type another one: '); $answer = fgets(STDIN, 4096); fwrite(STDOUT, 'You entered: ' . $answer); Edited July 26, 2014 by skroo Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now