Solved

Shell

Posted on 2001-06-27
4
358 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
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.

695 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