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

Features wanted...
Post Reply
Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

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

Post 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

Twisten
Posts: 204
Joined: 27 Apr 2008 10:30

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

Post 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).

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

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

Post 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]

Twisten
Posts: 204
Joined: 27 Apr 2008 10:30

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

Post 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.

admin
Site Admin
Posts: 64828
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

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

Post by admin »

I've looked into this some weeks ago, and did not see a good solution. I might look at it again later.

highend
Posts: 14562
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post 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
One of my scripts helped you out? Please donate via Paypal

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

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

Post 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

Post Reply