Groups | Blog | Home
all groups > visual c > april 2007 >

visual c : How do I execute a dos command from a .NET VC++ program


Kueishiong Tu
4/28/2007 10:36:00 PM
I have a .NET VC++ program, I want to execute some dos command from the
Kueishiong Tu
4/29/2007 1:52:02 AM
Dear Cholo:

Can you provide more details about the actual codings and how to pass the copy
command to cmd.exe.

I tried

System::Diagnostics::Process::Start ("cmd.exe", "copy FILEA FILEB");

But this does not work. The only thing the program does is to pop up the DOS
prompt command window without actually executing the copy command.

Also how to make the DOS prompt command window to go away from the program
after the copy command is done?


[quoted text, click to view]
Cholo Lennon
4/29/2007 3:32:20 AM
- (C/C++) std::system
- (C++ CLI) System::Diagnostics::Process::Start (in this case, you must use cmd.exe /k like a base process and a former command
line)


--
Cholo Lennon
Bs.As.
ARG


"Kueishiong Tu" <KueishiongTu@discussions.microsoft.com> escribió en el mensaje
news:70C9A954-B1FD-4AD8-BBCE-3B2058C71C96@microsoft.com...
[quoted text, click to view]

Cholo Lennon
4/29/2007 2:43:31 PM
You should use an extra parameter with cmd.exe (/k or /c) (check cmd help typing cmd /? ). Also you can use the && operator to
concatenate commands

Your code must look like this:

using namespace System::Diagnostics;.

// In one line
Process::Start("cmd.exe", "/c dir && pause");

// Executing with hidden console
ProcessStartInfo^ pSi = gcnew ProcessStartInfo("cmd.exe");
pSi->Arguments = "/c copy xxx yyy && delete xxx";
pSi->WindowStyle = ProcessWindowStyle::Hidden;
Process::Start(pSi);


--
Cholo Lennon
Bs.As.
ARG


"Kueishiong Tu" <KueishiongTu@discussions.microsoft.com> escribió en el mensaje
news:F4CD513F-E839-425D-99D9-00F24EB33B2D@microsoft.com...
[quoted text, click to view]

AddThis Social Bookmark Button