Sign in to follow this  
Followers 0
xManh

How to get the result from a Dos command

10 posts in this topic

For example I run a Dos command

Run(@ComSpec & " /c " & $command, "", @SW_HIDE)
    return $result

How to know if the command is successful?

thnx

Share this post


Link to post
Share on other sites



what command are you running ?


> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I'm fairly sure you may get a return of 1 or 0 by running @ComSpec directly.

$result = Run(@ComSpec & " /c " & $command, "", @SW_HIDE)
MsgBox(0, '', $result)

A cmd file in comparison can return varing int value from running a command.

:)

Edit:

Cmd file can use return values beyond the limit of 0 and 1.

Edited by MHz

Share this post


Link to post
Share on other sites

I'm not sure

It return variate integer values, some are very big (2023,3420,5050...)

Share this post


Link to post
Share on other sites

I'm fairly sure you may get a return of 1 or 0 by running @ComSpec directly.

$result = Run(@ComSpec & " /c " & $command, "", @SW_HIDE)
MsgBox(0, '', $result)
oÝ÷ Ø&uø¥z)Ü¢jZ®+(Ƨ­ën®{Ú®)à{oj[&®éçxr¦jwDv+B×âçë­ën®{Úç¬mì¨ÛazX¦ÚÑ©Ý×ú®¢×¶§Áó槵§Y¨­{-y§h}§N«zÛ«ö¥¹çë¢dn+-êk¡Ç¬°è~Ø^
¥ç¢{(êk¡Ç¬²)íç±jjexò¢ë¬y§Y¨­¶§ÚÞ¶êç²Ø^zºè®W¯zWë¢kayÊ&©ÝJ¨¹Æ§~ÞÅ©©è¶Ø^zºè®W¯zWë¢cDMDjëh×6$ExtCmd = "NET USE X: \\MyServer\MyShare * /USER:MyUser /PERSISTENT:NO"
$RetCode = RunWait($ExtCmd, @TempDir, @SW_MINIMIZE)
If $RetCode = 0 Then
     MsgBox(64, "Success", "Successfully mapped X: drive.")
Else
     MsgBox(16, "Error", "Error mapping X: drive, ERRORLEVEL = " & $RetCode)
EndIf

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Well I see. But is there a way to track the progress If I don't runwait.

Like Initget, I can choose 1 to download at background?

Share this post


Link to post
Share on other sites

Thanks for recommendation MHz

Share this post


Link to post
Share on other sites

Thanks for recommendation MHz

You still haven't said what $command was in your first example. If it outputs some kind of status to StdOut, then you can use Run() with $STDOUT_CHILD and the StdOutRead() function. Just another option... :)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

You still haven't said what $command was in your first example. If it outputs some kind of status to StdOut, then you can use Run() with $STDOUT_CHILD and the StdOutRead() function. Just another option... :lmao:

Heh...I like the stdout option, but have found an issue with it. Say your running the command 'findstr', and the file you are doing the search on does not contain the string you are looking for, a race condition is created. I've yet to find an elegant way around this, but I am still very new to autoit.

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  
Followers 0