Jump to content

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


uteotw
 Share

Recommended Posts

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
Link to comment
Share on other sites

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

;)

Link to comment
Share on other sites

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.

;)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...