Any way to interpret a command without running cmd.exe? - shell

I am looking for a way to run an executable or a script without getting cmd.exe to do it for me. Currently I'm launching a process using cmd.exe /C <command>, which I need to do the following things for me:
Look for the executable file in the current directory and PATH
Interpret PATHEXT to permit extension-less script commands
Interpret file associations to, e.g., run the python interpreter when I tell it to run blah.py.
I don't need to be able to run any of the "built-in" commands, like "dir".
Is it possible to avoid using cmd.exe without essentially re-implementing all of the above functionality? There must be some sort of shell API to do the above things, right?

ShellExecute should do exactly what you want - you can use it to launch an executable or a file (which is then opened with the standard application),
http://msdn.microsoft.com/en-us/library/bb762153%28v=vs.85%29.aspx

Take a look at System.Diagnostics.Process.Start( appName, args) .
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx and about the shell, have you looked it: http://msdn.microsoft.com/en-us/library/bb773177(v=vs.85).aspx ?

Related

Is there a command in Shell scripting for executing .exe file and running commands automatically inside of it? replacing the user interaction

I have a .sh script file that I'm modifying which runs an .EXE file that opens the Windows command line prompt automatically.
This .exe asks the user for an input (name of the file in the folder workspace that it will read)
I want to automate this step in my shell script so my user doesn't have to interact with this, and run the commands automatically
I read a bit about the expect command but I think that is for Linux only.
Can someone help me, I'm pretty new to Shell scripting and I couldn't find any useful information elsewhere.
I'm assuming that your executable accepts command-line arguments. So, here we go.
You can use the "start" command in Windows Shell. For example:
start C:\path\to\program.exe -argument
If you want to make the script wait until the .exe file finishes running before continuing, you can use the "/wait" command:
start /wait C:\path\to\program.exe -argument
IF all of that doesn't work, please try:
start myprogram.exe /command1 /command2 /command3
Hope it helps,

Start Command in CMD Window

I use below command in CMD window:
start notepad.exe
Is start a short-cut for an executable in Windows like:
C:\Windows\System32\start.exe
or is it a parameter to be passed to cmd.exe?
When I use
wcsript test.vbs
wcsript refers to
C:\Windows\System32\wcsript .exe
So I want to ask does same apply for start command?
Some commands available in CMD are built directly into CMD.EXE. I believe start, like dir, is one of those commands. You won't find a separate program called dir.exe or start.exe.
You do not need to use start, simply the location of your script with the filename+extension works.
The reason you can start notepad is because it is inside the Windows folder where CMD also is.
If it's on your desktop use: C:\Users\%Username%\Desktop\test.vbs
If you have multiple files you can make a script using:
cd C:\Users\%Username%\Desktop\
test1.vbs
test2.vbs

How to create an executable command prompt script

I usually perform actions in the 7zip command line program. I was thinking about creating a small script to do everything automatically, but I have never written any Windows shell script before and therefore don't even know where to begin.
I would like to make an executable script file which, when a user double-clicks on it, will call the 7zip command line and perform some actions.
First of all, is this possible? And if it is, what is the best way to do this?
You can create a batch script to do this.
It's basically command line commands that run one after another so you don't have to keep typing them in :)
Put the commands you would normally use for 7zip in a notepad file and save it with the extension .bat, then run it.
7z blah blah params
7z more params and args
All your commands will be executed automatically when the previous one finishes.
There are other programming languages you could do this in (or even VBScript) but batch would be perfectly suited to this, and you don't need to install anything extra.
Batch files can run a series of command line commands. Simply create a text file and name it with the .bat extension.
There are plenty of resources on the internet which will provide you with help.

From within a Rhino JS console run CD produces exception

When attempting runCommand("cd", "..") from inside a js.jar console an IOException is thrown.
I believe it's because in the command prompt the CD command is actually built into the console and not a separate .exe file. The runCommand("notepad") works fine, and that .exe can be found on the classpath in the usual location.
Is there a work around for this?
I was thinking that changing the directory through java instead of through the command prompt it might solve this problem, but I don't recall how to do that from java, but I plan on trying to figure that out.
To sum up: Is there a way to run "cd" from within a Rhino JS console on windows?
Thanks,
L-
Multiple issues to solve here; it depends what you are trying to do.
runCommand actually runs executable programs. cd is not an executable on Windows; it is a command in the command shell. So you would need to execute something more like this:
runCommand("cmd","/c","cd <target-directory>")
However, the underlying Java runtime does not allow you to actually change the working directory anyway. See this StackOverflow discussion. So shelling out cd just changes the directory for the subprocess (the process running cd), which is probably not what you want.

Batch Scripts - Need to specify to use an ANSI console and execute a command

This is a noob question at its best but Google isn't finding what I need.
I have a ruby script that I need to fire off via task scheduler. I thought I did it right by using the following:
cmd /k ruby test.rb
This works when starting the .bat file from the folder. However, if it runs from taskeng.exe it fails because its looking in my system32 folder. I don't want it to run from system32 so how do i format this to run from say, c:/dev/
Again, sorry for the extremely noob question.
You can leave out cmd of that and just use
ruby test.rb
or rather (in your case):
ruby C:\Users\Foo\test.rb
or something like that. Giving the complete path to the script usually helps in finding it ;-)
In any case, if you need the working directory you can set it in the scheduled task itself. Something akin to the following:
       
Likewise, if you actually need cmd in there. Just fill out the Start in field and you have a working directory.

Resources