Jump to content
Sign in to follow this  
uteotw

How to use StdinWrite() and StdoutRead() without closing the prompt?

Recommended Posts

uteotw

I understand how to use StdinWrite() and StdoutRead() but I don't want to close the DOS Prompt.

When I do

$PID = Run(@ComSpec, @SystemDir, @SW_SHOW)oÝ÷ Ù8^¦º&¦Û-k+(¥éÞu»­Â§!ÚºÚ"µÍÌÍÔQH[ÛÛTÜXËÞÝ[QÕ×ÔÒÕË   ÌÍÔÕSÐÒS
È  ÌÍÔÕÕUÐÒS

The prompt gets closed, but I'd like to keep it opened.

Is there a way?

thanks

Edited by uteotw

Share this post


Link to post
Share on other sites
MHz

I understand how to use StdinWrite() and StdoutRead() but I don't want to close the DOS Prompt.

If the script remains connected to the child process then it seems OK. If your script ends, then so does the child process.

This example works OK.

#include <Constants.au3>

Global $data, $title, $pid
$pid = Run(@ComSpec, @SystemDir, @SW_SHOW, $STDIN_CHILD + $STDOUT_CHILD)

If ProcessWait($pid, 5) Then
    _StdIn('help /?')
    _StdIn('copy /?')
    _StdIn('exit')
    ProcessWaitClose($pid)
EndIf

Exit

Func _StdIn($input)
    If Not ProcessExists($pid) Then Return
    $title = $input
    StdinWrite($pid, $input & @CRLF)
    If Not @error Then
        Sleep(100)
        _StdOut($data)
    EndIf
EndFunc

Func _StdOut(ByRef $output)
    If Not ProcessExists($pid) Then Return
    $output = StdOutRead($pid, 65500, True)
    Sleep(100)
    MsgBox(0x40000, $title, $data)
EndFunc

;)

Share this post


Link to post
Share on other sites
thijzzz

cool!

Really, i needed this for some time.

and my answer: remove the _StdIn('exit') from the example... ;-)

Share this post


Link to post
Share on other sites
MHz

cool!

Really, i needed this for some time.

and my answer: remove the _StdIn('exit') from the example... ;-)

Glad to help.

You do notice that _StdIn('exit') does exit the prompt, else how is it going to close? So it is needed at some point to politely close the prompt. Other examples on the forum may show @comSpec being used in command line mode by using the /c switch which will auto close the prompt.

;)

Share this post


Link to post
Share on other sites
uteotw

I get it to work the way I want now.

Thanks for all for your help.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.