?
Solved

Shell

Posted on 2001-06-27
4
Medium Priority
?
362 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 200 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

765 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