What is the best WinAPI function to use when you only want to run a simple shell command like hg > test.txt?
What is the best WinAPI function to use when you only want to run
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To simply run a file, then
ShellExecute()andCreateProcess()are the best options.As you want to redirect output to a file/run a shell command, it complicates things…
Output redirection is a feature of the command prompt, and as such, the command you want to run needs to be passed to
cmd.exe(on NT/XP+) passing/cand your command as the parameters (eitherShellExecuteorCreateProcesswill do).The best way however is to use
CreateProcess()and create your own pipes to talk to the stdin and stdout of the program (This is allcmddoes internally)