Jump to content

Recommended Posts

Posted

Hi:  I was trying to understand StdinWrite and have written the following two pieces of code.  The first without StninWrite works well, but the second does not.  Why?

Nazir

#include <Constants.au3>
$pid = Run("C:\Windows\system32\cmd.exe","C:\", $STDIN_CHILD + $STDOUT_CHILD)
WinWaitActive("C:\Windows\system32\cmd.exe")
send("cd ")
send("C:\users\test1")
send("{enter}")
Sleep(10000)
Exit
#include <Constants.au3>
$pid = Run("C:\Windows\system32\cmd.exe","C:\", $STDIN_CHILD + $STDOUT_CHILD)
WinWaitActive("C:\Windows\system32\cmd.exe")
StdinWrite($pid,"cd")
StdinWrite($pid,"C:\users\test1")
StdinWrite($pid,@CRLF)
Sleep(10000)
Exit

What am I doing wrong?

Regards,

Nazir

Posted

2 comments:

1- you forgot a space after "cd" in the problem code

2- stdinwrite returns the number of characters written, or sets @error. If you replace your "cd" line with this

Local $charnum = StdinWrite($pid,"cd ")

then have a msgbox to look at the value of $charnum, you will see that the code never reaches the msgbox statement.

According to help on stdinwrite, this means that "there is no room for more characters to be written to the stream". In other words, cmd.exe does not accept the input string, unless someone has a better interpretation of this problem.

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
×
×
  • Create New...