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

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

P: n/a
I have a .NET VC++ program, I want to execute some dos command from the
program, e.g. copy some file, and etc. How do I do that?
Apr 29 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
- (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" <Ku**********@discussions.microsoft.comescribió en el mensaje
news:70**********************************@microsof t.com...
>I have a .NET VC++ program, I want to execute some dos command from the
program, e.g. copy some file, and etc. How do I do that?

Apr 29 '07 #2

P: n/a
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?
"Cholo Lennon" wrote:
- (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" <Ku**********@discussions.microsoft.comescribió en el mensaje
news:70**********************************@microsof t.com...
I have a .NET VC++ program, I want to execute some dos command from the
program, e.g. copy some file, and etc. How do I do that?


Apr 29 '07 #3

P: n/a
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" <Ku**********@discussions.microsoft.comescribió en el mensaje
news:F4**********************************@microsof t.com...
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?
"Cholo Lennon" wrote:
>- (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" <Ku**********@discussions.microsoft.comescribió en el mensaje
news:70**********************************@microso ft.com...
>I have a .NET VC++ program, I want to execute some dos command from the
program, e.g. copy some file, and etc. How do I do that?



Apr 29 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.