Solved

Shell

Posted on 2001-06-27
4
337 Views
Last Modified: 2010-04-02
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
0
Comment
Question by:Luke_Stephens
4 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 6230713
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?
0
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 6230716
There is no Shell() command for C++ that I know of.  The MSDN docs lists shell commands for other langauges.

In C++, you would usually use the standard C++ system() command defined in <process.h>.   Like

system("dir c:\\" );

will perform a directory listing of the root of drive c.

0
 
LVL 30

Expert Comment

by:Axter
ID: 6230773
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.
0
 

Expert Comment

by:romilson
ID: 6231803
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
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Fully specialized class template function 21 136
FMX enumerated colours 2 101
gdb doesn't stop on breakpoint 2 68
Autosar OS Multicore Share Resources confusion ? 2 40
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question