Jump to content
Sign in to follow this  
mikelee33

@comspec using &&

Recommended Posts

mikelee33

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

Share this post


Link to post
Share on other sites
KaFu

You're trying to issue multiple commands to @comspec, right? Never got that working this way. The only way I succeeded was like shown in my Example 'Pipe to @ComSpec'.

Share this post


Link to post
Share on other sites
rasim

Never got that working this way.

Below code also not work for you?

RunWait(@ComSpec & " /k dir /b c: && Echo. && Echo finished")

Share this post


Link to post
Share on other sites
Inverted

Below code also not work for you?

RunWait(@ComSpec & " /k dir /b c: && Echo. && Echo finished")
This works great, nicely done !

Share this post


Link to post
Share on other sites
KaFu

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

Share this post


Link to post
Share on other sites
mikelee33

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?

Share this post


Link to post
Share on other sites
rasim

@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

Share this post


Link to post
Share on other sites
KaFu

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

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.