Solved

Shell

Posted on 2001-06-27
4
328 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now