Page 1 of 1

Scripting: run() as function with get return code / errorlev

Posted: 29 Jan 2012 18:04
by Stefan
I want to suggest to turn SC run into an function which can return the return code of the called app
(and even the whole stdout and stderr ?)


$uccess = run(%comspec% /c myApp para1);

If ($uccess == 0){msg "all went fine"}else{break;}





error level errorlevel return code returncode

Re: Scripting: run() as function with get return code / erro

Posted: 30 Jan 2012 05:51
by Twisten
+1 for error code return, also it would finally allow us to script synchronous scripts that call outside programs (i.e. it would wait for run to end instead of the script running ahead).
I would suggest that if it's desirable for run() to return its own error codes that the return value would be 'called program's return code'*1000;
Which would leave 0 as 0 and other codes you'll differentiate by length.

Edit: As for stdout/err I suppose that the function could receive two optional variables for that (if its possible for XYplorer to capture them).

Re: Scripting: run() as function with get return code / erro

Posted: 30 Jan 2012 06:32
by Stefan
Twisten wrote:+1 for error code return, also it would finally allow us to script synchronous scripts that call outside programs (i.e. it would wait for run to end instead of the script running ahead).
This part is already possible:

run command, [directory], [wait=0], [show=1]

Re: Scripting: run() as function with get return code / erro

Posted: 30 Jan 2012 06:39
by Twisten
Mmm, nope.
If you use 'wait=1' you're stuck until the program is finished, can't use XYplorer at all.
If you use 'wait=0' you run uncontrollably ahead and if you're in a loop that calls that command you might end up with multiple instances of a possibly resource demanding command.
If on the other hand run is a function and therefore the script doesn't move past it until it returns the value, your script can run without interrupting normal usage.

Re: Scripting: run() as function with get return code / erro

Posted: 30 Jan 2012 09:52
by admin
I've looked into this some weeks ago, and did not see a good solution. I might look at it again later.

Re: Scripting: run() as function with get return code / erro

Posted: 30 Jan 2012 11:40
by highend
I'd love to see that as well...

Atm, I'm using this approach (rudimentary but it works for me):
http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=7490

Re: Scripting: run() as function with get return code / erro

Posted: 22 May 2014 15:27
by TheQwerty
admin wrote:I've looked into this some weeks ago, and did not see a good solution. I might look at it again later.
Once again find myself missing a nice clean way to capture command output in a script.

Had you seen this when you looked into it last?
http://www.vbforums.com/showthread.php? ... the-output