本文整理汇总了C#中System.Diagnostics.Process.Start方法的典型用法代码示例。如果您正苦于以下问题:C# Process.Start方法的具体用法?C# Process.Start怎么用?C# Process.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.Process
的用法示例。
在下文中一共展示了Process.Start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: cmd
public String cmd(String cnd)
{
cnd = cnd.Trim();
String output = " ";
Console.WriteLine(cnd);
if ((cnd.Substring(0, 3).ToLower() == "cd_") && (cnd.Length > 2))
{
if (System.IO.Directory.Exists(cnd.Substring(2).Trim()))
cpath = cnd.Substring(2).Trim();
}
else
{
cnd = cnd.Insert(0, "/B /c ");
Process p = new Process();
p.StartInfo.WorkingDirectory = cpath;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = cnd;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
output = p.StandardOutput.ReadToEnd(); // output of cmd
output = (output.Length == 0) ? " " : output;
p.WaitForExit();
}
return output;
} // end cmd
示例2: System
public System(string cmd)
{
string[] v = cmd.Split(new Char[] { ' ', '\t' }, 2);
if (v.Length < 1)
throw new ArgumentException("Invalid command");
string prog = v[0];
string args = v.Length > 1 ? v[1] : "";
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.FileName = prog;
p.StartInfo.Arguments = args;
try
{
p.Start();
}
catch
{
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/c " + cmd;
p.Start();
}
_err = p.StandardError.ReadToEnd();
_out = p.StandardOutput.ReadToEnd();
p.WaitForExit();
}
示例3: AddSimpleRectoSvn
public static void AddSimpleRectoSvn(string inputDir)
{
try {
Process p = new Process();
p.StartInfo.FileName = "svn";
p.StartInfo.Arguments = "add -N " + inputDir + @"\*";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = false;
p.Start();
string output = p.StartInfo.Arguments + "\r\n";
output = output + p.StandardOutput.ReadToEnd();
p.WaitForExit();
p = new Process();
p.StartInfo.FileName = "svn";
p.StartInfo.Arguments = "commit " + inputDir + "\\* -m\"addedFiles\"";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = false;
p.Start();
p.WaitForExit();
} catch (Exception ex) {
MessageBox.Show(ex.Message, "SVN checkout issue");
}
}
示例4: RunProgam
static public bool RunProgam(String asFile, String asArgs)
{
Process myProcess = new Process();
try
{
myProcess.StartInfo.FileName = asFile;
myProcess.StartInfo.Arguments = asArgs;
myProcess.Start();
}
catch (Win32Exception e)
{
if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
{
return false;
}
else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
{
return false;
}
}
return true;
}
示例5: generateKeypair
/// <summary>
/// Generate a keypair
/// </summary>
public static void generateKeypair()
{
// We need both, the Public and Private Key
// Public Key to send to Gitlab
// Private Key to connect to Gitlab later
if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\.ssh\id_rsa.pub") &&
File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\.ssh\id_rsa"))
{
return;
}
try {
Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\.ssh");
} catch (Exception) {}
Process p = new Process();
p.StartInfo.FileName = "ssh-keygen";
p.StartInfo.Arguments = "-t rsa -f \"" + Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\.ssh\\id_rsa\" -N \"\"";
p.Start();
Console.WriteLine();
Console.WriteLine("Waiting for SSH Key to be generated ...");
p.WaitForExit();
while (!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\.ssh\id_rsa.pub") &&
!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\.ssh\id_rsa"))
{
Thread.Sleep(1000);
}
Console.WriteLine("SSH Key generated successfully!");
}
示例6: aa
public void aa()
{
//实例化一个进程类
cmd = new Process();
//获得系统信息,使用的是 systeminfo.exe 这个控制台程序
cmd.StartInfo.FileName = "cmd.exe";
//将cmd的标准输入和输出全部重定向到.NET的程序里
cmd.StartInfo.UseShellExecute = false; //此处必须为false否则引发异常
cmd.StartInfo.RedirectStandardInput = true; //标准输入
cmd.StartInfo.RedirectStandardOutput = true; //标准输出
cmd.StartInfo.RedirectStandardError = true;
//不显示命令行窗口界面
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
cmd.Start(); //启动进程
cmd.StandardInput.WriteLine("jdf b");
//cmd.StandardInput.WriteLine("exit");
//获取输出
//需要说明的:此处是指明开始获取,要获取的内容,
//<span style="color: #FF0000;">只有等进程退出后才能真正拿到</span>
//cmd.WaitForExit();//等待控制台程序执行完成
//cmd.Close();//关闭该进程
Thread oThread1 = new Thread(new ThreadStart(bb));
oThread1.Start();
}
示例7: RunProcess
private string RunProcess(string commandName, string arguments, bool useShell)
{
System.Windows.Forms.Cursor oldCursor = System.Windows.Forms.Cursor.Current;
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
Process p = new Process();
p.StartInfo.CreateNoWindow = !useShell;
p.StartInfo.UseShellExecute = useShell;
p.StartInfo.Arguments = arguments;
p.StartInfo.RedirectStandardOutput = !useShell;
p.StartInfo.RedirectStandardError = !useShell;
p.StartInfo.FileName = commandName;
p.Start();
if(!useShell)
{
string output = p.StandardOutput.ReadToEnd();
string error = p.StandardError.ReadToEnd();
p.WaitForExit();
WriteToConsole(error);
WriteToConsole(output);
System.Windows.Forms.Cursor.Current = oldCursor;
return output;
}
return "";
}
示例8: Main
static void Main(string[] args)
{
List<string> start_for = new List<string>();
start_for.Add(@"C:\\xampp\\mysql\\bin\\mysqld.exe");//mysql路徑
start_for.Add(@"C:\\xampp\\apache\\bin\\httpd.exe");//apache路徑
start_for.Add("netsh wlan stop hostednetwork");//wifi stop
start_for.Add("netsh wlan set hostednetwork mode=allow ssid=Apple-steven-wifi key=0000000000123");//wifi set
start_for.Add("netsh wlan start hostednetwork");//cmd 指令
//Process p = new Process();
//p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
int i = 0;
foreach (string C_val in start_for)
{
Process SomeProgram = new Process();
SomeProgram.StartInfo.FileName = (i == 2 || i == 3 || i == 4) ? "cmd.exe" : C_val;
SomeProgram.StartInfo.Arguments = @"/c " + C_val;
//p.StartInfo.Arguments = "/c " + command;
SomeProgram.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;//不要有視窗
SomeProgram.Start();
i++;
}
}
示例9: Button1Click
void Button1Click(object sender, EventArgs e)
{
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(@"C:\Users\IJMAIL\AppData\Roaming\Nox\bin\nox_adb.exe" );
myProcessStartInfo.Arguments = "devices";
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true; // 데이터 받기
myProcessStartInfo.RedirectStandardError = true; // 오류내용 받기
myProcessStartInfo.CreateNoWindow = true; // 원도우창 띄우기(true 띄우지 않기, false 띄우기)
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
myProcess.WaitForExit();
//string output = myProcess.StandardOutput.ReadToEnd();
string output = myProcess.StandardOutput.ReadToEnd();
string error = myProcess.StandardError.ReadToEnd();
string[] aa = output.Split('\n');
for(int i=1; i<aa.Length; i++) {
listBox1.Items.Add(aa[i]);
}
//listBox1.Items.Add(aa.Length);
//listBox1.Items.Add(aa[1]);
//listBox1.Text = output;
// 프로그램이 종료되면
//System.Console.WriteLine( "ExitCode is " + myProcess.ExitCode );
myProcess.WaitForExit();
myProcess.Close();
}
示例10: AssembleFile
public static string AssembleFile(string ilFile, string outFile, bool debug)
{
if (!File.Exists(ilFile))
{
throw new FileNotFoundException("IL file \"" + ilFile + "\" not found.");
}
File.Delete(outFile);
Process proc = new Process();
proc.StartInfo.FileName = "\"" + GetIlasmPath() + "\"";
proc.StartInfo.Arguments = "\"" + ilFile + "\" /out=\"" + outFile + "\" /dll" + (debug ? " /debug" : "");
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.Start();
string stdout = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();
if (!File.Exists(outFile))
{
throw new Exception("File \"" + ilFile + "\" could not be assembled.");
}
return stdout;
}
示例11: ExecuteUtilityAsync
void ExecuteUtilityAsync(string args, Action<string> parseOutput, Action onComplete)
{
Process p = new Process();
p.StartInfo.FileName = Utility;
p.StartInfo.Arguments = args;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
var t = new Thread( _ =>
{
using (var reader = p.StandardOutput)
{
// This is wrong, chrisf knows why
while (!p.HasExited)
{
string s = reader.ReadLine();
if (string.IsNullOrEmpty(s)) continue;
parseOutput(s);
}
}
onComplete();
}) { IsBackground = true };
t.Start();
}
示例12: StartSteamAccount
public bool StartSteamAccount(SteamAccount a)
{
bool finished = false;
if(IsSteamRunning())
{
KillSteam();
}
while (finished == false)
{
if (IsSteamRunning() == false)
{
Process p = new Process();
if (File.Exists(installDir))
{
p.StartInfo = new ProcessStartInfo(installDir, a.getStartParameters());
p.Start();
finished = true;
return true;
}
}
}
return false;
}
示例13: Pack_Works
public void Pack_Works()
{
string pathToNuGet = MakeAbsolute(@".nuget\NuGet.exe");
string pathToNuSpec = MakeAbsolute(@"src\app\SharpRaven\SharpRaven.nuspec");
ProcessStartInfo start = new ProcessStartInfo(pathToNuGet)
{
Arguments = String.Format(
"Pack {0} -Version {1} -Properties Configuration=Release -Properties \"ReleaseNotes=Test\"",
pathToNuSpec,
typeof(IRavenClient).Assembly.GetName().Version),
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
WindowStyle = ProcessWindowStyle.Hidden,
};
using (var process = new Process())
{
process.OutputDataReceived += (s, e) => Console.WriteLine(e.Data);
process.ErrorDataReceived += (s, e) => Console.WriteLine(e.Data);
process.StartInfo = start;
Assert.That(process.Start(), Is.True, "The NuGet process couldn't start.");
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit(3000);
Assert.That(process.ExitCode, Is.EqualTo(0), "The NuGet process exited with an unexpected code.");
}
}
示例14: ExecuteSync
public void ExecuteSync(string fileName, string arguments, string workingDirectory)
{
if (string.IsNullOrWhiteSpace(fileName))
throw new ArgumentException("fileName");
var process = new Process {
StartInfo = {
FileName = fileName,
Arguments = arguments,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
WorkingDirectory = workingDirectory
},
};
process.OutputDataReceived += Process_OutputDataReceived;
process.ErrorDataReceived += Process_ErrorDataReceived;
process.Exited += Process_Exited;
try {
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
} catch (Win32Exception) {
throw new ExecuteFileNotFoundException(fileName);
}
}
示例15: ayudaToolStripMenuItem_Click
private void ayudaToolStripMenuItem_Click(object sender, EventArgs e)
{
Process pr = new Process();
pr.StartInfo.WorkingDirectory = @"C:\Users\Wilfredo\Desktop\admin\admin\admin";
pr.StartInfo.FileName = "SofTool Systems help.htm";
pr.Start();
}