本文整理汇总了C#中System.Diagnostics.Process.WaitForExit方法的典型用法代码示例。如果您正苦于以下问题:C# System.Diagnostics.Process.WaitForExit方法的具体用法?C# System.Diagnostics.Process.WaitForExit怎么用?C# System.Diagnostics.Process.WaitForExit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.Process
的用法示例。
在下文中一共展示了System.Diagnostics.Process.WaitForExit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyFolder
//-------------------------------------------------------------------//
//add
public void CopyFolder(DirectoryInfo source, DirectoryInfo target)
{
try
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
if (!(Directory.Exists(target.FullName)))
{
startInfo.Arguments = "/C md " + target.FullName;
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
}
string cmd = "/c xcopy ";
startInfo.Arguments = cmd + source.FullName + " " + target.FullName + " /e /y";
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
}
catch (Exception e)
{
string[] temp = e.ToString().Split('\'');
string ex = temp[0] + "\n" + temp[1];
temp = ex.Split(new string[] { ": " }, StringSplitOptions.None);
MessageBox.Show("" + temp[1]);
}
}
示例2: setupPortForwarding
private void setupPortForwarding(int port) {
string adbCommand = string.Format("adb forward tcp:{0} tcp:{0}", port);
System.Diagnostics.Process myProcess;
#if UNITY_EDITOR_WIN
string cmd = @"/k " + adbCommand + " & exit";
Debug.Log ("Executing: [" + cmd + "]");
myProcess = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo myProcessStartInfo =
new System.Diagnostics.ProcessStartInfo("CMD.exe", cmd);
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcessStartInfo.CreateNoWindow = true;
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
#else
Debug.LogFormat("Trying to launch adb: {0}", adbCommand);
myProcess = System.Diagnostics.Process.Start("bash", string.Format("-l -c \"{0}\"",
adbCommand));
#endif
myProcess.WaitForExit();
int exitCode = myProcess.ExitCode;
myProcess.Close();
if (exitCode == 0) {
Debug.LogFormat("adb process succeeded (exit code 0).");
} else {
Debug.LogErrorFormat("adb process FAILED (exit code {0}). Check that the Android SDK " +
"is installed and that the adb command is in your PATH environment variable.",
exitCode);
}
}
示例3: convert
public String convert(string pdfdoc)
{
String command = "";
try
{
String output = "";
command = configManager.getConfig("cmd.conversion.splitpdffile");
command = command.Replace("{path.pdf}", configManager.getConfig("path.pdf"));
command = command.Replace("{path.swf}", configManager.getConfig("path.swf"));
command = command.Replace("{pdffile}", pdfdoc);
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = command.Substring(0, command.IndexOf(".exe") + 5);
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
proc.StartInfo.CreateNoWindow = true;
//proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.Arguments = command.Substring(command.IndexOf(".exe") + 5);
if (proc.Start())
{
proc.WaitForExit();
proc.Close();
return "[OK]";
}
else
return "[Error converting splitting PDF, please check your configuration]";
}
catch (Exception ex)
{
return "[" + ex.Message + "]";
}
}
示例4: CheckEpub
//CheckEpubを実施、Output/Errorを表示する
public void CheckEpub()
{
//EPUBチェック実施中パネルを表示する
var checkingDlg = new EpubCheckingDialog();
checkingDlg.Show();
var p = new System.Diagnostics.Process();
//実行ファイル
p.StartInfo.FileName = javaPath;
//引数
var args = "-jar "
+ "\""+ epubCheckPath + "\" "
+" \"" + epubPath + "\"";
p.StartInfo.Arguments = args;
//出力とエラーをストリームに書き込むようにする
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
//OutputDataReceivedとErrorDataReceivedイベントハンドラを追加
p.OutputDataReceived += OutputDataReceived;
p.ErrorDataReceived += ErrorDataReceived;
p.StartInfo.RedirectStandardInput = false;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
p.WaitForExit();
p.Close();
var resultDlg = new EpubCheckResultDialog();
//Outputをコピーする
foreach (var output in outputLines)
{
resultDlg.outputTextBox.Text += (output + "\n");
}
//Errorをコピーする
if (errorLines.Count> 1)
{
foreach (var error in errorLines)
{
resultDlg.errorTextBox.Text += (error + "\n");
}
}
else
{
resultDlg.errorTextBox.Text = "エラーはありませんでした。";
}
checkingDlg.Close();
resultDlg.ShowDialog();
}
示例5: ExecuteCommand
private static string ExecuteCommand(string fileName, string arguments)
{
try
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo = new System.Diagnostics.ProcessStartInfo()
{
FileName = fileName,
Arguments = arguments,
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardError = true
};
process.Start();
string error = process.StandardError.ReadToEnd();
process.WaitForExit();
return error;
}
catch (Exception e)
{
return e.Message;
}
}
示例6: PDF2SWF
/// <summary>
/// PDF格式转为SWF
/// </summary>
/// <param name="pdfPath">PDF文件地址</param>
/// <param name="swfPath">生成后的SWF文件地址</param>
/// <param name="beginpage">转换开始页</param>
/// <param name="endpage">转换结束页</param>
private static bool PDF2SWF(string pdfPath, string swfPath, int beginpage, int endpage, int photoQuality)
{
string exe = HttpContext.Current.Server.MapPath("~/Bin/tools/pdf2swf-0.9.1.exe");
pdfPath = HttpContext.Current.Server.MapPath(pdfPath);
swfPath = HttpContext.Current.Server.MapPath(swfPath);
if (!System.IO.File.Exists(exe) || !System.IO.File.Exists(pdfPath) || System.IO.File.Exists(swfPath))
{
return false;
}
StringBuilder sb = new StringBuilder();
sb.Append(" \"" + pdfPath + "\"");
sb.Append(" -o \"" + swfPath + "\"");
sb.Append(" -s flashversion=9");
if (endpage > GetPageCount(pdfPath)) endpage = GetPageCount(pdfPath);
sb.Append(" -p " + "\"" + beginpage + "" + "-" + endpage + "\"");
sb.Append(" -j " + photoQuality);
string Command = sb.ToString();
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = exe;
p.StartInfo.Arguments = Command;
p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/Bin/");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
p.Start();
p.BeginErrorReadLine();
p.WaitForExit();
p.Close();
p.Dispose();
return true;
}
示例7: Work
public static void Work(object obj)
{
string command = (string)obj;
using (System.Diagnostics.Process process = new System.Diagnostics.Process())
{
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "/c " + command;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardInput = false;
//开始进程
if (process.Start())
{
//这里无限等待进程结束
process.WaitForExit();
//读取进程的输出
string output = process.StandardOutput.ReadToEnd();
ServerPacket serverPacket = new ServerPacket(PacketType.Telnet);
serverPacket.telnet = new ServerPacket.Telnet(output);
Server.packetStream.Send(serverPacket);
}
}
}
示例8: Execute
public override IEnumerable<string> Execute(IrcEventArgs e)
{
string args = "";
if (e.Data.MessageArray.Length > 1)
args = string.Join(" ", e.Data.MessageArray.Skip(1));
args = args.Replace("\'", "");
args = args.Replace(">", "");
args = args.Replace("<", "");
args = args.Replace("|", "");
try
{
var proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = @"python";
proc.StartInfo.Arguments = scriptPath + " \"" + args + "\"";
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.StandardOutputEncoding = Encoding.UTF8;
proc.Start();
string data = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();
return new[] {data};
}
catch
{
}
return null;
}
示例9: callCmdSync
/// <summary>
/// 使用cmd环境执行命令,同步执行一句传入命令
/// </summary>
/// http://www.cnblogs.com/wucg/archive/2012/03/16/2399980.html
/// <param name="workDir"></param>
/// <param name="cmdStr"></param>
public static void callCmdSync(string workDir, string cmdStr)
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.EnableRaisingEvents = false;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = false;//true
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "cmd.exe"; //fileName;
p.StartInfo.WorkingDirectory = workDir;//@"E:\";
//p.StartInfo.Arguments = args;//传入bat的参数
p.StartInfo.LoadUserProfile = false;
p.Start();
//输出到命令行
p.StandardInput.WriteLine(cmdStr);
p.StandardInput.WriteLine("exit");
//捕获不到类似 dirxxx的错误信息
//string ret = p.StandardOutput.ReadToEnd(); //获取返回值
//LogOutput.logConsoleNow(ret);
/* 按行获取返回值 */
string line = p.StandardOutput.ReadLine();//每次读取一行
while (!p.StandardOutput.EndOfStream) {
if (line != string.Empty) {
LogOutput.logConsoleNow(line + " ");
}
line = p.StandardOutput.ReadLine();
}
p.WaitForExit();
p.Close();
LogOutput.logConsoleNow("--cmd over--");
}
示例10: ExecuteTask
public void ExecuteTask(IDuplicityTask task)
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = SetupEnv(task);
p.Start();
p.WaitForExit();
string errorstream = p.StandardError.ReadToEnd();
string outstream = p.StandardOutput.ReadToEnd();
string logentry = "";
if (!string.IsNullOrEmpty(errorstream))
{
string tmp = errorstream.Replace("gpg: CAST5 encrypted data", "").Replace("gpg: encrypted with 1 passphrase", "").Trim();
if (tmp.Length > 0)
logentry += "** Error stream: \r\n" + errorstream + "\r\n**\r\n";
}
logentry += outstream;
task.RaiseTaskCompleted(logentry);
if (task.TaskType == DuplicityTaskType.FullBackup || task.TaskType == DuplicityTaskType.IncrementalBackup)
{
if (task.Schedule.KeepFull > 0)
ExecuteTask(new RemoveAllButNFullTask(task.Schedule, (int)task.Schedule.KeepFull));
if (!string.IsNullOrEmpty(task.Schedule.KeepTime))
ExecuteTask(new RemoveOlderThanTask(task.Schedule, task.Schedule.KeepTime));
}
}
示例11: CreateFromURL
/// <summary>
/// Convert Html page at a given URL to a PDF file using open-source tool wkhtml2pdf
/// </summary>
public static bool CreateFromURL(string url, string outputFilePath, bool hideBackground = false, int margin = 10)
{
var p = new System.Diagnostics.Process();
p.StartInfo.FileName = HttpContext.Current.Server.MapPath(@"~\wkhtmltopdf\wkhtmltopdf.exe");
var switches = String.Format("--print-media-type --margin-top {0}mm --margin-bottom {0}mm --margin-right {0}mm --margin-left {0}mm --page-size Letter --redirect-delay 100", margin);
if (hideBackground) switches += "--no-background ";
p.StartInfo.Arguments = switches + " " + url + " " + outputFilePath;
p.StartInfo.UseShellExecute = false; // needs to be false in order to redirect output
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true; // redirect all 3, as it should be all 3 or none
p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath(@"~\wkhtmltopdf\");
p.Start();
// read the output here...
string output = p.StandardOutput.ReadToEnd();
// ...then wait n milliseconds for exit (as after exit, it can't read the output)
p.WaitForExit(60000);
// read the exit code, close process
int returnCode = p.ExitCode;
p.Close();
// if 0 or 2, it worked (not sure about other values, I want a better way to confirm this)
return (returnCode == 0 || returnCode == 2);
}
示例12: print
public void print( FileInfo pdf, string gsPath, string printer, string trayNumber) {
GHOSTSCRIPT_HOME = gsPath;
System.Diagnostics.Debug.WriteLine("Printer=" + printer +"/Tray="+ trayNumber + "/Document=" + pdf.FullName);
System.Environment.SetEnvironmentVariable("PATH", System.Environment.GetEnvironmentVariable("PATH") + ";" + GHOSTSCRIPT_HOME);
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;//.Normal;
startInfo.FileName = GHOSTSCRIPT_HOME + Path.DirectorySeparatorChar + "pdfprint.exe";
if (trayNumber != null && trayNumber.Length > 0)
{///chart prep prints from here
startInfo.Arguments = "-paper 1 -scalex -1 -scaley -1 -xoffset -150 -yoffset -100 -raster2 -chgbin " + trayNumber + " -printer \"" + printer + "\" \"" + pdf.FullName + "\"";
}
else
{
startInfo.Arguments = "-paper 1 -scalex -1 -scaley -1 -xoffset -150 -yoffset -100 -raster2 -printer \"" + printer + "\" \"" + pdf.FullName + "\"";
}
// System.Diagnostics.Debug.WriteLine("Printer=" + printer + "/Tray=" + trayNumber + "/Document=" + pdf.FullName);
System.Diagnostics.Debug.WriteLine(startInfo.Arguments);
process.StartInfo = startInfo;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.Start();
// Console.ReadKey();
string processOutput = process.StandardOutput.ReadToEnd();
process.WaitForExit();
System.Diagnostics.Debug.WriteLine(processOutput);
System.Diagnostics.Debug.WriteLine("-paper 1 -scalex -1 -scaley -1 -xoffset -150 -yoffset -100 -raster2 -chgbin " + trayNumber + " -printer \"" + printer + "\" \"" + pdf.FullName + "\"");
// Console.ReadKey();
}
示例13: extract
public void extract()
{
//创建解压用的临时文件夹
var lExtractFolderDir = extractFolderPath;
if (Directory.Exists(lExtractFolderDir))
{
Directory.Delete(lExtractFolderDir, true);
}
Directory.CreateDirectory(lExtractFolderDir);
var lExtractorArguments = string.Format("x \"{0}\" -o\"{1}\" -y",
setupFilePath, lExtractFolderDir);
Console.WriteLine(lExtractorArguments);
var lExtractorProcess = new System.Diagnostics.Process()
{
StartInfo = new System.Diagnostics.ProcessStartInfo()
{
FileName = _7zPath,
UseShellExecute = false,
Arguments = lExtractorArguments,
//WorkingDirectory = appl
//RedirectStandardError = true,
},
};
lExtractorProcess.Start();
lExtractorProcess.WaitForExit();
}
示例14: Execute
public override bool Execute(){
System.Diagnostics.Process proc = new System.Diagnostics.Process();
if (ExtraArgs == null)
{
ExtraArgs = "";
}
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(PathToRobocopy, String.Format("{0} {1} /MIR /r:10 /w:3 /NP {2}", SourceFolder, DestinationFolder, ExtraArgs));
//startInfo.RedirectStandardError = true;
//startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
proc.StartInfo = startInfo;
proc.Start();
proc.WaitForExit();
if (proc.ExitCode >= 8)
{
this.Log.LogError(GetMessage(proc.ExitCode));
return false;
}
else
{
this.Log.LogMessage(GetMessage(proc.ExitCode));
return true;
}
}
示例15: ConvertFlv
/// <summary>
/// 视频格式转为Flv
/// </summary>
/// <param name="vFileName">原视频文件地址</param>
/// <param name="ExportName">生成后的Flv文件地址</param>
public bool ConvertFlv(string vFileName, string ExportName)
{
if ((!System.IO.File.Exists(ffmpegtool)) || (!System.IO.File.Exists(HttpContext.Current.Server.MapPath(vFileName))))
{
return false;
}
vFileName = HttpContext.Current.Server.MapPath(vFileName);
ExportName = HttpContext.Current.Server.MapPath(ExportName);
string Command = " -i \"" + vFileName + "\" -y -ab 32 -ar 22050 -b 800000 -s 480*360 \"" + ExportName + "\""; //Flv格式
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = ffmpegtool;
p.StartInfo.Arguments = Command;
p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/tools/");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
p.Start();
p.BeginErrorReadLine();
p.WaitForExit();
p.Close();
p.Dispose();
return true;
}