Link to home
Start Free TrialLog in
Avatar of Luke_Stephens
Luke_Stephens

asked on

Shell

We're trying to run a batch file using the shell command.  Can anyone give us the code to do this?  We've tried the shell command that is given in the MSDN help file but we're getting errors.

Cheers,
Luke
Avatar of jhance
jhance

Please be more specific in your question:

>>We've tried the shell command that

What shell command?  How are your using it?

>>but we're getting errors.

What errors?  Runtime?  Compile/Link?  What?
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Axter
If you're trying to launch another program from your program, VC++ has several methods for doing this.
_spawn(), _exec(), system(), WinExec(), ShellExecute(), ShellExecuteEx(), and CreateProcess()

For more information, see following link:
http://www.axter.com/faq/topic.asp?TOPIC_ID=24&FORUM_ID=4&CAT_ID=9&Topic_Title=How+to+launch+a+program+from+another+program+in+VC&Forum_Title=C%2FC%2B%2B

The CreateProcess() functions gives you the most control, but it's a bit tricky to use.
In the above link, there's a wrapper class for CreateProcess() function.  The wrapper class is called  CreateProcessMngr

It's at the bottom of the page.
the system("program.bat") call is the best way to it.
your executable must to be in the same directory of the batch file or you must to put the location to the batch file.
system("c:\bach_files\program.bat");

include file : process.h
prototipe: int system( const char *command );

"Return Value

If command is NULL and the command interpreter is found, the function returns a nonzero value. If the command interpreter is not found, it returns 0 and sets errno to ENOENT. If command is not NULL, system returns the value that is returned by the command interpreter. It returns the value 0 only if the command interpreter returns the value 0. A return value of ? 1 indicates an error, and errno is set to one of the following values:

E2BIG
Argument list (which is system-dependent) is too big.

ENOENT
Command interpreter cannot be found.

ENOEXEC
Command-interpreter file has invalid format and is not executable.

ENOMEM
Not enough memory is available to execute command; or available memory has been corrupted; or invalid block exists, indicating that process making call was not allocated properly. "  >> MSDN reference

thats all !

Romilson