Jump to content

@comspec using &&


Recommended Posts

I simply can not get the syntax correct to utilize '&&' in the following line:

RunWait (@comspec & ' /k ' &$prog &' '&$option&' '&GUICtrlRead($file)''&&'echo Finished!')

I think I'm close, but I'm not certain. Many thanks for any direction.

Mike

Link to comment
Share on other sites

Link to comment
Share on other sites

Below code also not work for you?

RunWait(@ComSpec & " /k dir /b c: && Echo. && Echo finished")
Yeah, you're right :), works for me this way. Forgot that he's running it without pipes. What didn't work for me was piping several commands to stdout using one instance of @comspec that way (e.g. to chcp):

#include <Constants.au3>
$foo = Run(@ComSpec & " /k dir /b c: && Echo. && Echo finished", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
$line = ""
While 1
    $line &= StdoutRead($foo)
    If @error Then ExitLoop
Wend
MsgBox(0,"","Finished" & @crlf & @crlf & @crlf & $line)





$foo = Run(@ComSpec, "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
StdinWrite($foo, "dir /b c:" & @CRLF)
StdinWrite($foo, "echo. Echo finished" & @CRLF)
StdinWrite($foo, "exit" & @CRLF); send exit command to trigger stdout
$line = ""
While 1
    $line &= StdoutRead($foo)
    If @error Then ExitLoop
Wend
MsgBox(0,"","Finished" & @crlf & @crlf & @crlf & $line)
Edited by KaFu
Link to comment
Share on other sites

Try this:

RunWait(@ComSpec & ' /k ' & $prog & ' ' & $option & ' ' & GUICtrlRead($file) & ' & & echo Finished!')
Sorry, no, that didn't work for me. The first command executed, but not the echo.

Your second example: RunWait(@ComSpec & " /k dir /b c: && Echo. && Echo finished") does work as you've written it but when I apply that approach it didn't work. Might it be how the first program terminates that causes an issue with how the second executes?

Link to comment
Share on other sites

@KaFu

Your first example contain error, you not indicate a working directory :)

@mikelee33

Sorry, no, that didn't work for me. The first command executed, but not the echo.

Your second example: RunWait(@ComSpec & " /k dir /b c: && Echo. && Echo finished") does work as you've written it but when I apply that approach it didn't work. Might it be how the first program terminates that causes an issue with how the second executes?

Meaning:

Command1 && Command2; Run second command if first command executed successfully
Command1 || Command2; Run second command if first command executed unsuccessfully
Link to comment
Share on other sites

You're right... but you'll have also to append an Exit to trigger the stdout, then it works both ways, you'll live while you learn :)...

#include <Constants.au3>
; Example 1
$foo = Run(@ComSpec, "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
StdinWrite($foo, "dir /b c:" & @CRLF)
StdinWrite($foo, "echo. Echo finished" & @CRLF)
StdinWrite($foo, "exit" & @CRLF); send exit command to trigger stdout
$line = ""
While 1
    $line &= StdoutRead($foo)
    If @error Then ExitLoop
Wend
MsgBox(0,"","Finished" & @crlf & @crlf & @crlf & $line)


; Example 2
$foo = Run(@ComSpec & " /k dir /b c: && Echo. && Echo finished && Exit", 'c:\', @SW_HIDE, $STDOUT_CHILD)

$line = ""
While 1
    $line &= StdoutRead($foo)
    If @error Then ExitLoop
Wend
MsgBox(0,"","Finished" & @crlf & @crlf & @crlf & $line)

(updated my example 'Pipe to @ComSpec')

Best Regards

Edited by KaFu
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...