By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,916 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,916 IT Pros & Developers. It's quick & easy.

How to get a DOS cmd output to CString or equivalent using MFC?

P: 13

Just wondering if anyone knew how to run a DOS cmd such as "ping", and get the output to a CString variable to process using MFC? I'm currently using something like:

WinExec("cmd /c \"ping localhost > textfile\"", SW_HIDE);

Which copies the output of the ping to the file "textfile". I'd like to skip the step to read in a file, then process it.

Thanks in advanced!
May 8 '08 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 5K+
P: 9,197
Did you read this in MSDN?

WinExec("C:\\Program Files\\MyApp", ...)

If a malicious user were to create an application called "Program.exe" on a system, any program that incorrectly calls WinExec using the Program Files directory will run this application instead of the intended application.

To avoid this problem, use CreateProcess rather than WinExec. However, if you must use WinExec for legacy reasons, make sure the application name is enclosed in quotation marks as shown in the example below.
May 8 '08 #2

P: 13
Did you read this in MSDN?
Yes I did, but I don't think it helped, and not to mention the security risks of the function. I'm investigating CreateProcess(), but it seems like a pretty involved solution, which I'm hoping to avoid by asking some experts.
May 8 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.