Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difference between .run & .exec

Status
Not open for further replies.

mark01

Technical User
Jan 17, 2001
600
US
I noticed that when I use WShell.run & WShell.exec in a script, there is a difference. When using WShell.run, it will execute both .exe & .bat, but will not execute a path with spaces in it. (c:\program files\) When using WShell.exec, it will not run .bat's but it will run a path that has spaces.

Is there anyway I can use just one of these commands, and get all the functionality of both???

For example, I'd like to run the file c:\program files\test.bat.

thx
 
Hello mark01,

Just a couple of things that are worthwhile to keep in mind.

[1] .Exec method is introduced in wsh5.6, so when there a script throws a runtime error on it, one thing to check is the versioning.

[2] .Exec always exec the commandline asynchronously and the script will proceed to the next lines after firing it. .Run takes instruction from the scripter on the 3rd parameter.

[3] .Exec returns a WshShellExec object which exposes notably stdin, stdout and stderr. This is the main added functionality where .Run lacks in case there is a need. .Run return just an integer.

[4] .Run has the advantage of hidding the application running whereas .Exec lacks this control.

[5] As .Exec runs asynchronously, its return object provides further .state property to let user enquire the status of the execution. .Run lacks such functionality.

[5] .Exec return object provides .Terminate method to terminate the process. .Run process let loose and out of its control. If anything goes wrong, you have to go to task manager to terminate the process.

To my understanding, it is not .Exec necessarily superior to .Run. Its implementation certainly tries to provide useful functionality that earlier implementation of .run lacks. If those added functionalities are in need, then no doubt you have to use .Exec.

regards - tsuji

PS: I do not touch on your observations made, I do not think it is of any generic interest. There are sure some know-hows to keep in mind when dealing with space and platforms.
 
To avoid problem with spaces in path you can do this:
Code:
strcmd=Chr(34) & "c:\program files\test.bat" & Chr(34)
And then call the Run method.

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top