Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / April 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kueishiong Tu - 29 Apr 2007 06:36 GMT
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?
Cholo Lennon - 29 Apr 2007 07:32 GMT
- (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

>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?
Kueishiong Tu - 29 Apr 2007 09:52 GMT
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?

> - (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
[quoted text clipped - 7 lines]
> >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?
Cholo Lennon - 29 Apr 2007 18:43 GMT
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

> Dear Cholo:
>
[quoted text clipped - 22 lines]
>> >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?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.