473,473 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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
3 6457
- (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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: tom | last post by:
Problem: In PHP, need to execute a program in (freebsd terms) /usr/local/bin in meta-terms: int i; i = (arguments); There seems to be quite a few execution methods in PHP (sorry in advance...
6
by: Joseph | last post by:
Hi, I am trying to develop a C# application that will run on Windows that will do the following * Select file name to process * FTP the file to a UNIX server * Process this file on UNIX using a...
9
by: Jaime | last post by:
I am using Microsoft Visual C++ and i have some projects configuration. (Configuration A, Configuration B, ..., Configuration N) I need to execute some system operation call such as copy, delete,...
4
by: Chris | last post by:
I posted this in the C# language group, then thought it might be more appropriate in this group. I would not cross-post except I want the answer so badly. I built small C# Web and Web Service...
5
by: Good Man | last post by:
Hi there I am trying to execute a custom-built java program on my linux server via PHP. Basically, a user uploads files via PHP, and then the java program performs some action on these files. ...
4
by: alberto | last post by:
How can I execute a command of the operating system like "cls" from a C# code? Thank you
3
by: =?Utf-8?B?S3VlaXNoaW9uZyBUdQ==?= | last post by:
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?
0
by: chandan agarwal | last post by:
hi I have been given the task of building vc++ programs at the command line using make software. i have installed gnu make-3.81 version. i was able to build and run makefiles for turbo c++. but...
2
by: revenant81 | last post by:
I'm writing a program which has to execute a command, get its output and show it on a treeview. This command runs for a very long time. I want to end the execution of the command when the user...
2
by: sdanda | last post by:
Hi, I am working on C#. We have a tool called WHOST.exe which is a VC++ MFC application. Recently I modified the application and regenerated the WHOST.exe in Visual Studio 2008. If i open the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.