Call another application or command line (. exe with parameters) in C #

Source: Internet
Author: User
Tags command line

Using system.diaglostics.Process in. NET can be used to invoke another command line or program.

Using System.Diagnostics;

If it's a DOS

Process.Start ("cmd.exe");

If it is another file

Process.Start ("absolute path + filename. exe");

------------------------------------

How do I call an external DOS program in C #?

Working with Process objects:

 System.Diagnostics.Process   p=new   System.Diagnostics.Process();
  p.StartInfo.FileName="arj.exe"   ;//需要启动的程序名
  p.StartInfo.Arguments="-x   sourceFile.Arj   c:temp";//启动参数
  p.Start();//启动
  if(p.HasExisted)//判断是否运行结束
   p.kill();

---------------------------------------------------------------------------------------- ------

<summary>
To start another application
</summary>
<param name= "File" > Application name </param>
<param name= "Workdirectory" > Application working directory </param>
<param name= "args" > Command line Arguments </param>
<param name= "style" > Window style </param>
public static bool StartProcess (string file,string workdirectory,string Args,processwindowstyle style)
{
Try
{
Process myprocess = new process ();
ProcessStartInfo startinfo = new ProcessStartInfo (File,args);
Startinfo.windowstyle = style;
Startinfo.workingdirectory = workdirectory;
Myprocess. StartInfo = StartInfo;
Myprocess. Startinfo.useshellexecute = false;
Myprocess. Start ();
return true;
}
catch (Exception E0)
{
MessageBox.Show ("Error starting application!") Reason: "+ E0." message);
}
return false;
}

String parms = "" + globalobject.getinstance (). UserID + "" + globalobject.getinstance (). UserPassword;
if (publicmethods.startprocess (Application.startuppath + @ "Uptooluptool.exe", Application.startuppath + "Uptool", Parms,processwindowstyle.normal))
{
Environment.exit (0);
}
---------------------------------------------------------------------------- ----------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.