473,386 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 6453
- (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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.