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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with WSH and .Run command

Status
Not open for further replies.

chickety

Programmer
Dec 11, 2002
3
US
I need to be able to run multiple commands in the same cmd session. What I mean is, I need for the commands to remember the previous command, so I believe it has to run in the same cmd session. I also don't want to have to create a batch file and have the VBScript run the batch file. That would be easy. I want all of the commands to be in the VBScript.

Here is an example of what I am trying to do (not my real code):

Set WshShell = CreateObject("WScript.Shell")

WshShell.Run "cmd /c SET ENVVAR = chickety", 1, TRUE
WshShell.Run "cmd /c SET ENVVAR >C:\example.txt", 1, TRUE

Now if I did these commands in a regular cmd window outside of VBScript, I would get ENVVAR = chickety as the answer to the second command. But in VBScript, I get nothing back. How do I get it to remember the previous command. I tried using cmd /k to no avail, I also tried 0, TRUE. I am obviously a beginner at this, but I need your help. What can I do? PLEASE HELP, this is driving me crazy!
 
Chickety

What exactly are you trying to do? - this may sound like an obvious point but you can use the FileSystemObject to write to text files and use your script to store varible values.

If you need to run a series of DOS commands as a batch then use the FileSystemObject to create a new .bat file, write the commands to this file then run this .bat from the script and delete it after it has executed.

Let me know if this helps or for more details of FileSystemObject.

-Sunny
 
You can also set environment variables from within VBScript.

Example:

Set WshEnv = WshShell.Environment("System")
WshEnv("ENVVAR") = "chickety"

See for more detail on what you can get out of WshShell.Environment.

Dana Hallenbeck
 
Well I am not trying to set environmental variables, I just used it as an example.

Here are the DOS commands that I would like to run in VBScript:

"C:\Apps\Microsoft Visual Studio\VSS\win32\ss.exe" Cp "$/Globaltracs/v 1.0/dbms/DBA Scripts"
"C:\Apps\Microsoft Visual Studio\VSS\win32\ss.exe" Workfold "$/Globaltracs/v 1.0/dbms/DBA Scripts" C:\VSS
"C:\Apps\Microsoft Visual Studio\VSS\win32\ss.exe" Checkin GT_Updates.sql

When the third command runs, it has to remember the previous two commands. When you do this in a cmd window, it works fine, but when I run it in VBScript just using cmd /c, it forgets the previous two commands. I modified the VBScript to call a batch file with these commands in it and it works fine, but I didn't want to call other files.
 
Chickety

Have you tried actually running ss.exe with the wshell.run method directly and not using cmd? It may be worth a quick try to see if ss.exe will hold the WorkFold when run directly from the script.

If this does not work then you have only 2 choices - call the batch file like you mentionned or if this is not an option then follow my suggestion and temporarily create the batch file from within the script, run it and then delete it!

-Sunny

 
There is a COM object that will capture output of a dos command and let you use that output within the script. You can download it from:

Look for "CaptureConsoleOutput (tbxwxcex.dll)..." on the page for the download point. I have used this several times with much success.

Dana Hallenbeck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top