Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using system(...) to run external applications 1

Status
Not open for further replies.

perplexd

Programmer
May 9, 2002
154
US
I've been told that using system(...) to run external applications is bad practice.

Currently I'm using the following line of code:

system("a:\\Extract.exe /Y/A/E/L "+targetDir+" a:\\TSPDv.cab");

This is supposed to extract a cab file to targetDir. If this really is bad programming practice can someone tell me what I should do??? Otherwise this seems to work fine for my requirements. (I am only writing a small program to extract a number of files to a certain specified directory and a few other minor tasks.)

Thanks
 
>I've been told that using system(...) to run external applications is bad practice.

It is. Use ShellExecute (or ShellExecuteEx) instead.

>system("a:\\Extract.exe /Y/A/E/L "+targetDir+" a:\\TSPDv.cab");

Code:
ShellExecute(NULL, //HWND
             "open" // operation
             "a:\\Extract.exe", // file
             "/Y/A/E/L "+targetDir+" a:\\TSPDv.cab" // Parameters
             NULL, // directory
             SW_HIDE // show cmd);

/Per
[sub]Nerdy signatures are as lame as the inconsistent stardates of STTNG.[/sub]
 
If you want the added functionality of blocking on the spawned process use CreateProcess(..) and then WaitForSingleObject(..) using the handle to the process that was obtained from the creation.

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top