We help IT Professionals succeed at work.

Execution dos command through VC++

gourav_jain
gourav_jain asked
on
1,570 Views
Last Modified: 2008-03-03
Hi,

I want to execute a dos based utility using my VC++ program and display the output generated by the program in the GUI. There are few ways to do this one is to use the system command but my utility take 5-10 secs. to complete and for this time the system command shows the dos window on top of everything.
The other way is to use the PIPE open the command output in the pipe and display the result but in that way as well the DOS window pops up.
Is there any way to achive this in which the utility will be executed in the background and i will get the output in a buffer.

Gourav Jain
Comment
Watch Question

Commented:
Do u have the source code for the utility OR its a standard DOS utility

Amit

Author

Commented:
I dont have the source code of that utility
Gourav Jain

Commented:
In what manner do You start  utilty?
In case

WinExec(...,SW_HIDE);

In case
CreateProcess();
in structure STARTUPINFO wShowWindow = SW_HIDE;
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
AxterSenior Software Engineer
CERTIFIED EXPERT

Commented:
A simple way is to use DOS redirect method.
Example:

system("myprog.exe > datafile.txt");

The above command will put the output into datafile.txt file.
AxterSenior Software Engineer
CERTIFIED EXPERT

Commented:
If you want to hide the process, you can use WinExec with the redirect command.

Example:
WinExec("myprog.exe > datafile.txt",SW_HIDE);
jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
>>WinExec("myprog.exe > datafile.txt",SW_HIDE);

*Cough*

WinExec("cmd.exe /c myprog.exe > datafile.txt",SW_HIDE);


BTW, a full sample on how to do that can be found at http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q190/3/51.ASP&NoWebContent=1 ("HOWTO: Spawn Console Processes with Redirected Standard Handles")
A small doubt: Where is WinExec() function defined?
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.