How can I manipulate the command line through VBScript? - vbscript

Could anyone give me example code to access the command line through VBScript? I want to execute two commands respectively in a command prompt.
For example, first command: cd C:\a, second command: winzip32.exe -min -a D:\d.

you can use wshell.Run. The other one is wshell.exec

Put your commands in a .cmd or .bat file and then run that. You could even build the batch file inside your script if it is not static.
MyBatch.cmd
CD C:\a
winzip32.exe -min -a D:\d
MyScript.vbs
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "MyBatch.cmd"

Related

Shell script execution in ssis

I have a file with extention .sh(shell script).
I need execute this file in ssis using execute process task.
how can i do this.
Please help me!!!
Code inside .sh file :echo SSIS test >> /home/junaib/test/sql.txt (for testing)
If you enabled WSL and you sure that the commands work from command line then you can run the command on cmd.exe with the /c flag
Executable : cmd.exe
Arguments : /c "BASH C:\SO\test.sh"

Execute several commands in one line, and save stdout into a file

In a batch file, I am trying to execute several commands in a single line:
start cmd /c "title SomeTitle & python SomeFile.py 1>SomeFile.txt & timeout /t -1"
The output file SomeFile.txt is created empty, and everything is printed directly to the terminal.
I've tried putting the python SomeFile.py 1>SomeFile.txt part within double-quotes.
However, I then get a The system cannot find the path specified error.
How can I work around this?

nircmd: I can't run another batch file with nircmd.exe?

I have wrote a batch file that i want to run another program with nircmd.exe. But the problem is i can't run it? The batch file(Matrix.bat) runs correctlyby double-click it. But when i trying to open it with nircmd.exe, it doesn't run? why?
i tried two method:
RunMethod1.bat (for runing another batch file)
SET INSTALLPATH=d:\atlantic
start %INSTALLPATH%\nircmd exec show %INSTALLPATH%\Matrix.bat
RunMethod1.bat (for runing another batch file)
SET INSTALLPATH=d:\atlantic
%INSTALLPATH%\nircmd exec show %INSTALLPATH%\Matrix.bat
The exec command in nircmd does not run batch files but executable files. Change your code to
start "" "%INSTALLPATH%\nircmd.exe" exec show "%comspec%" "%INSTALLPATH%\Matrix.bat"
Now, nircmd executes a cmd instance that will handle the batch file execution
The problem was in path of nircmd.exe. I set path of nircmd but i didn't know why it isn't work correctly? with "pushd" command i set the path of cmd into where nircmd.exe exist. and Bow!!! everything works cerrectly. Maybe a syntax problem. If everyone know that say it here.
SET INSTALLPATH=d:\atlantic
pushd %INSTALLPATH%
nircmd exec show Matrix.bat

Simple CMD argument throught VBScript

Its been a while...
I have the command line arg:
xml sel -t -v "computer/general/name" nsk1501901173m.xml > test.txt
that produces the results I want in the text document specified but I need to run it through a VBScript and for the life of me I cannot figure it out... any ideas?
You must use the WScript.Shell object to execute the app and the cmd /c (command shell with the /C parameter) before to pass your app arguments , check this sample
Set objShell = CreateObject("WScript.Shell")
objShell.run "cmd /c xml sel -t -v ""computer/general/name"" nsk1501901173m.xml > test.txt",1,true
Remember which script must be executed from the same location where the xml.exe app is located or even better add the location of xml.exe app to the PATH

Launch new command line and exucte in that shell

This must be a real dumb question. And I cant figure out how.
What I want to do is launch a new command line with some arguments and excute some commands there.
Here is what I have in my .cmd
CMD /k %EnvInstallPath% %wo% %var%
cd /d %wo%\src
When I execute test.cmd, I see that the directory changes to %wo%, but the further cd src is not executed. I need to cd to a directory and execute few other commands.
When you run cmd with /k the console runs the command and then resumes with the prompt. I'm guessing that what you want is to run the command and resume with the next one, so you need to run cmd with /c instead.
put the other commands in a different bat file and
start AFewOtherCommands.bat

Resources