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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Weegee
    New Member
    • Mar 2008
    • 13

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

    Hello,

    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!
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Did you read this in MSDN?

    Originally posted by MSDN
    WinExec("C:\\Pr ogram Files\\MyApp", ...)

    If a malicious user were to create an application called "Program.ex e" 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.
    http://msdn.microsoft.com/en-us/libr...93(vs.85).aspx.

    Comment

    • Weegee
      New Member
      • Mar 2008
      • 13

      #3
      Originally posted by weaknessforcats
      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.

      Comment

      Working...