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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending Text to Command Prompt?

Status
Not open for further replies.

amadeolr

Technical User
Jan 4, 2005
4
0
0
US
I am attempting to write a C++ console application that will do the following:
Open up a Command Prompt window.
Pass a text string to the Command Prompt (like “del filename.txt”).
The Command Prompt will execute the command and then return control to the C++ program.

I am using CreateProcess to invoke the Command Prompt window. I am not sure how to send a string to the Command Prompt window. I saw the function called SendMessage. Would SendMessage be the best/easiest way to send a text string to the Command Prompt?

Thanks
 
Why do you need to open the command prompt window in the first place? Why not just use the [tt]system()[/tt] function?
 
Ok, the system() function is exactly what I needed. This is much better solution compared to what I was trying. Thanks.
 
If all you want to do is delete a file, the C function for it is remove. eg
Code:
remove ("filename.txt")
unlink does the same thing on MS but not on Unix. There is also rename for renaming files.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top