本文整理汇总了C#中System.Diagnostics.Process类的典型用法代码示例。如果您正苦于以下问题:C# Process类的具体用法?C# Process怎么用?C# Process使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Process类属于System.Diagnostics命名空间,在下文中一共展示了Process类的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: Runcmd
public string Runcmd()
{
Process myProcess = new Process();
myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.RedirectStandardError = true;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StartInfo.RedirectStandardOutput = true;
try
{
myProcess.Start();
}
catch (Exception)
{
throw;
}
try
{
foreach (var item in Cmds)
{
myProcess.StandardInput.WriteLine(item);
}
}
catch (Exception)
{
throw;
}
myProcess.StandardInput.WriteLine("exit");
return myProcess.StandardOutput.ReadToEnd();
}
示例3: 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!");
}
示例4: Snes
public Snes()
{
mProcess = SearchProcess("snes9x.exe");
mProcessPtr = OpenProcess(ProcessAccessFlags.PROCESS_VM_READ, false, mProcess.Id);
updateMemory();
}
示例5: B_start_Click
private void B_start_Click(object sender, EventArgs e)
{
AccountCacher = new Process();
AccountCacher.StartInfo.FileName = "AccountCacher.exe";
AccountCacher.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
AccountCacher.Start();
Thread.Sleep(500);
LauncherServer = new Process();
LauncherServer.StartInfo.FileName = "LauncherServer.exe";
LauncherServer.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
LauncherServer.Start();
Thread.Sleep(500);
LobbyServer = new Process();
LobbyServer.StartInfo.FileName = "LobbyServer.exe";
LobbyServer.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
LobbyServer.Start();
Thread.Sleep(500);
WorldServer = new Process();
WorldServer.StartInfo.FileName = "WorldServer.exe";
WorldServer.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
WorldServer.Start();
}
示例6: GetThumbnailFromProcess
private MemoryStream GetThumbnailFromProcess(Process p, ref int width, ref int height)
{
Debug("Starting ffmpeg");
using (var thumb = new MemoryStream()) {
var pump = new StreamPump(p.StandardOutput.BaseStream, thumb, null, 4096);
if (!p.WaitForExit(20000)) {
p.Kill();
throw new ArgumentException("ffmpeg timed out");
}
if (p.ExitCode != 0) {
throw new ArgumentException("ffmpeg does not understand the stream");
}
Debug("Done ffmpeg");
if (!pump.Wait(2000)) {
throw new ArgumentException("stream reading timed out");
}
if (thumb.Length == 0) {
throw new ArgumentException("ffmpeg did not produce a result");
}
using (var img = Image.FromStream(thumb)) {
using (var scaled = ThumbnailMaker.ResizeImage(img, ref width, ref height)) {
var rv = new MemoryStream();
try {
scaled.Save(rv, ImageFormat.Jpeg);
return rv;
}
catch (Exception) {
rv.Dispose();
throw;
}
}
}
}
}
示例7: ProcessInfo
private Dictionary<int, ThreadInfo> processThreads; //has relating thread id to its threadInfo object
#endregion Fields
#region Constructors
/// <summary>
/// Constructor for ProcessInfo
/// </summary>
/// <param name="procID">The id of the process</param>
/// <param name="debugger">The debugger</param>
public ProcessInfo(Process process, CorDebugger debug)
{
if (debug == null)
{
throw new ArgumentException("Null Debugger Exception");
}
processThreads = new Dictionary<int, ThreadInfo>();
processCorThreads = new List<CorThread>();
generalThreadInfos = new Dictionary<int, ProcessThread>();
attachedCompletedProcessEvent = new ManualResetEvent(false);
debugger = debug;
processId = process.Id;
generalProcessInfo = Process.GetProcessById(processId);
//CorPublish cp = new CorPublish();
//cpp = cp.GetProcess(processId);
processFullName = process.MainModule.FileName;
processShortName = System.IO.Path.GetFileName(process.MainModule.FileName);
FileVersionInfo fileInfo = FileVersionInfo.GetVersionInfo(processFullName);
description = fileInfo.FileDescription;
company = fileInfo.CompanyName;
//debuggerProcessInfo will be set when the updateInfo function is called
//the reason for this is that the process must be stopped for this to take place
//this happen only when we want it to
}
示例8: AbortedShutdown
internal void AbortedShutdown()
{
if(_ShutdownProcess != null && !_ShutdownProcess.HasExited)
_ShutdownProcess.Kill();
_ShutdownProcess = null;
_Main.StopTimer();
}
示例9: 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");
}
}
示例10: 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;
}
示例11: BuildPSAttack
public static int BuildPSAttack(Attack attack, GeneratedStrings generatedStrings)
{
//DateTime now = DateTime.Now;
//string buildDate = String.Format("{0:MMMM dd yyyy} at {0:hh:mm:ss tt}", now);
//using (StreamWriter buildDateFile = new StreamWriter(Path.Combine(attack.resources_dir, "attackDate.txt")))
//{
// buildDateFile.Write(buildDate);
//}
string dotNetDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
string msbuildPath = Path.Combine(dotNetDir, "msbuild.exe");
if (File.Exists(msbuildPath))
{
Process msbuild = new Process();
msbuild.StartInfo.FileName = msbuildPath;
msbuild.StartInfo.Arguments = attack.build_args(Path.Combine(Strings.obfuscatedSourceDir, generatedStrings.Store["psaReplacement"] + ".sln"));
msbuild.StartInfo.UseShellExecute = false;
msbuild.StartInfo.RedirectStandardOutput = true;
msbuild.StartInfo.RedirectStandardError = true;
Console.WriteLine("Running build with this command: {0} {1}", msbuild.StartInfo.FileName, msbuild.StartInfo.Arguments);
msbuild.Start();
string output = msbuild.StandardOutput.ReadToEnd();
Console.WriteLine(output);
string err = msbuild.StandardError.ReadToEnd();
Console.WriteLine(err);
msbuild.WaitForExit();
int exitCode = msbuild.ExitCode;
msbuild.Close();
return exitCode;
}
return 999;
}
示例12: 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();
}
示例13: 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();
}
示例14: _load
private void _load(Process proc) {
File = new FileInfo(ProcessExecutablePath(proc));
Name = proc.ProcessName;
Id = proc.Id;
Thread = new Thread(Monitor);
Thread.Start(this);
}
示例15: tcpRouteStart
void tcpRouteStart()
{
tcpRoute = new Process();
tcpRoute.StartInfo.FileName = "TcpRoute2.exe";
tcpRoute.StartInfo.WorkingDirectory = ".";
tcpRoute.StartInfo.Arguments = "";
tcpRoute.StartInfo.CreateNoWindow = true;
// tcpRoute.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
tcpRoute.StartInfo.UseShellExecute = false;
tcpRoute.StartInfo.RedirectStandardOutput = true;
tcpRoute.StartInfo.StandardOutputEncoding = Encoding.UTF8;
tcpRoute.StartInfo.StandardErrorEncoding = Encoding.UTF8;
tcpRoute.StartInfo.RedirectStandardError = true;
// 注册关闭事件
tcpRoute.EnableRaisingEvents = true;
tcpRoute.SynchronizingObject = this;
tcpRoute.Exited += new EventHandler(TcpRouteExit);
tcpRoute.OutputDataReceived += new DataReceivedEventHandler(process1_ErrorDataReceived);
tcpRoute.ErrorDataReceived += new DataReceivedEventHandler(process1_ErrorDataReceived);
tcpRoute.Start();
tcpRoute.BeginOutputReadLine();
tcpRoute.BeginErrorReadLine();
// tcpRoute.WaitForExit();
}