[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Start a proccess from C# in the background

Posted on 2009-12-26
4
Medium Priority
?
652 Views
Last Modified: 2013-12-17
Dear Eperts,

I would like to start an external command line application from csharp. I have already found a code to do that, but when I run it, it runs the "external" cmd proccess in front of me (like when I start it from cmd.exe). I would like to ask you to show me a code which I can use for running this application with it's arguments, but in the background. So I don't want to see any command line interface popping up. Please, if you have any suggestions to do that, post it to me.

Thank you really much,
Chris
0
Comment
Question by:mkrisz
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
lenordiste earned 1600 total points
ID: 26125534
here is what you can do:
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo.FileName = "cmd.exe";
            proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            proc.StartInfo.CreateNoWindow = true;
            proc.Start();
0
 
LVL 11

Assisted Solution

by:nordtorp
nordtorp earned 400 total points
ID: 26125543
Then remember to do proc.kill() when you want to end it, else it will run after you terminate your application.
0
 
LVL 11

Expert Comment

by:lenordiste
ID: 26125545
here is an even nicer example from (http://www.developer.com/net/csharp/article.php/3707996/NET-Tip-Execute-Commands-From-C.htm):
public static int ExecuteCommand(string Command, int Timeout)
{
   int ExitCode;
   ProcessStartInfo ProcessInfo;
   Process Process;

   ProcessInfo = new ProcessStartInfo("cmd.exe", "/C " + Command);
   ProcessInfo.CreateNoWindow = true;
   ProcessInfo.UseShellExecute = false;
   Process = Process.Start(ProcessInfo);
   Process.WaitForExit(Timeout);
   ExitCode = Process.ExitCode;
   Process.Close();

   return ExitCode;
}

0
 
LVL 5

Author Closing Comment

by:mkrisz
ID: 31670102
Lenordiste, you forgot the arguments, but I did that, so no problem :) Great solution, thanks.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Simple Linear Regression

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question