473,326 Members | 2,061 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,326 software developers and data experts.

How to execute program with command line?

RA
Hi

I have a windows form app and I need to execute a program when the user
chooses an option. How do I start a program from code, with command line
arguments and getting the return value from that program?
Thanks
Nov 15 '05 #1
6 10658
RA,

You will want to call the static Start method on the Process class,
passing the command line to the method. You can also create an instance of
the Process class and then call the Run method on it, and you should be able
to get the return value after the execution completes.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"RA" <ro****@hotmail.com> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...
Hi

I have a windows form app and I need to execute a program when the user
chooses an option. How do I start a program from code, with command line
arguments and getting the return value from that program?
Thanks

Nov 15 '05 #2
Use Process.Start( program to start, attributes to pass);

program to start is a path to the .exe of the application to start
attributes to pass is a string containing attributes as You would write them
calling app manually.

You could use String builder to create attributes, something like this:

string[] args = new string[4];
args[0] = " -o";
args[1] = scriptFolder;
args[2] = "_script.txt";
args[3] = _thumbnail.sImagePath;
StringBuilder arguments = new StringBuilder();
foreach(string arg in args)
{
arguments.Append(arg + " ");
}
Process.Start(Preferences.distFix_PTPath , arguments.ToString());

or

Simply build a attribute string like this :
string arguments = " -o " + scriptFolder + " _script.txt " +
_thumbnail.sImagePath;
Process.Start(Preferences.distFix_PTPath , arguments);
Nov 16 '05 #3
I was able to find it in System.Diagnostics. The basic problem was
when I typed Process.Start(); I got errors. I needed the
System.Diagnostics to place before it.

Nov 16 '05 #4
Thanks. Found it in System.Diagnostics.

Nov 16 '05 #5
Thanks. I found it in System.Diagnostics. Nice code snippet on
StringBuilder.

Nov 16 '05 #6
This is a very innefficient way of coding. Have you ever thought about
writing better code?
Currently you have 4 strings in memory, which you then put into an Array,
then loop through appending them to a stringbuilder (which will copy them),
then you ToString() the stringbuilder, copying the string again to pass to
Process.Start()
As it is all hardcoded anyway you would be better off just passing a single
string to the function which would take up less memory and shorten the JIT
Compilation process.

Ciaran

"CroDude" <di***********@zg.htnet.hr> wrote in message
news:cr**********@news1.xnet.hr...
Use Process.Start( program to start, attributes to pass);

program to start is a path to the .exe of the application to start
attributes to pass is a string containing attributes as You would write
them
calling app manually.

You could use String builder to create attributes, something like this:

string[] args = new string[4];
args[0] = " -o";
args[1] = scriptFolder;
args[2] = "_script.txt";
args[3] = _thumbnail.sImagePath;
StringBuilder arguments = new StringBuilder();
foreach(string arg in args)
{
arguments.Append(arg + " ");
}
Process.Start(Preferences.distFix_PTPath , arguments.ToString());

or

Simply build a attribute string like this :
string arguments = " -o " + scriptFolder + " _script.txt " +
_thumbnail.sImagePath;
Process.Start(Preferences.distFix_PTPath , arguments);

Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: joe | last post by:
Hello, I have the following commands: testb -s <size> testb -s <size> -o <input file> testb -s <size> -o <codes> How do i split the commands so that all three are valid. And how do i check...
1
by: Matt | last post by:
I used to execute a command line script in IIS 4 using Dynuexec. This is a third part server object I installed on the server (http://www.dynu.com/dynuexec.asp). I installed this object onto my...
1
by: ktsirig | last post by:
Hi all, I need to execute a command-line program through PHP. I have a form which includes a textarea, where the user writes his data. These data will be used as input for the command-line...
5
by: randyelliott | last post by:
Good Day, I have a MS Access (Access 2000 now upgraded to 2003) database that tracks customer information. One function of this database is to create an encrypted license file for our software,...
2
by: Adam Clauss | last post by:
I am building a GUI to wrap around some of the information/abilities contained within the program netsh. I have figured out how to use redirect the standardinput and standardoutput so that I can...
6
by: Lucas Cowald | last post by:
Hi, I need to RUN/execute a Command-Line command from an ASP page. This is the command: sse45.exe -i k:\o\2.wmv -o k:\o\2.shh -w 128 -df 0 -m 2 -p Can you show me a code how to run this...
1
by: stikhs | last post by:
Hi! I want to execute a command line application through my programme!Is there any instruction that could help me do this?I want to give the arguments via the GUI that I build,so is it possible...
0
by: drken567 | last post by:
I'm trying to execute a command line from my C++ .NET code/WinXP. The program (call it myprog.exe) is located in a directory (C:\mypath) which is included in the system 'path' environment variable....
2
by: Jim | last post by:
Hello, I need a program that will traverse a directory tree to ensure that there are unix-style line endings on every file in that tree that is a text file. To tell text files from others I...
7
by: swethak | last post by:
Hi, i have a command to convert the video file into image ffmpeg -i sample.wmv -f image2 -t 0.001 -ss 3 ss.jpg i run that one in command prompt it converted the video file into...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.