我在Windows应用程序中尝试运行另一个应用程序,它是tetpdflib。该tetpdflib只在命令提示符下运行。当我拖放EXE到命令提示符时,它会执行。对于我跟着一些编码在windows应用程序中执行的命令提示符命令
Process tetmlProcess = new Process();
tetmlProcess.StartInfo.CreateNoWindow = true;
tetmlProcess.StartInfo.RedirectStandardOutput = true;
tetmlProcess.StartInfo.UseShellExecute = false;
tetmlProcess.StartInfo.FileName = @"cmd.exe";
tetmlProcess.StartInfo.Arguments = "cd C:\\Users\\sw_chn\\Documents\\PDFlib\\TET 5.0 32-bit\\bin\\tet.exe";
tetmlProcess.Start();
,但我不能让输出..而我也需要运行以下命令提示符行也
CD tet.exe 和TET -m名
如何在该过程中执行那些命令。
这就是完整的编码
public static string inputfile = string.Empty;
public static string outputfolder = string.Empty;
private void btninputbrowse_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog inputFileBrowser = new OpenFileDialog();
DialogResult result = inputFileBrowser.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
inputfile = inputFileBrowser.FileName;
txtinput.Text = inputFileBrowser.FileName;
}
}
private void btnoutputbrowse_Click(object sender, RoutedEventArgs e)
{
FolderBrowserDialog folderbrowsing = new FolderBrowserDialog();
DialogResult result = folderbrowsing.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
outputfolder = folderbrowsing.SelectedPath;
txtoutput.Text = folderbrowsing.SelectedPath;
}
}
private void btnok_Click(object sender, RoutedEventArgs e)
{
MoveInputFileToOutPutFolder();
}
private void MoveInputFileToOutPutFolder()
{
try
{
string[] splitinput = inputfile.Split('\\');
outputfolder = System.IO.Path.Combine(outputfolder,splitinput.LastOrDefault());
if (File.Exists(outputfolder))
{
File.Delete(outputfolder);
}
File.Copy(inputfile,outputfolder);
TetmlApplicationRunning();
}
catch (Exception)
{
throw;
}
}
private void TetmlApplicationRunning()
{
try
{
Process tetmlProcess = new Process();
//tetmlProcess.StartInfo.CreateNoWindow = true;
//tetmlProcess.StartInfo.RedirectStandardOutput = true;
//tetmlProcess.StartInfo.UseShellExecute = false;
tetmlProcess.StartInfo.FileName = @"C:\\Users\\sw_chn\\Documents\\PDFlib\\TET 5.0 32-bit\\bin\\tet.exe";
tetmlProcess.StartInfo.WorkingDirectory = @"C:\\Users\\sw_chn\\Documents\\PDFlib\\TET 5.0 32-bit\\bin";
tetmlProcess.StartInfo.Arguments = "tetml -m wordplus" + inputfile;
tetmlProcess.Start();
}
catch (Exception)
{
throw;
}
}
}
}
可能是您需要设置[WorkingDirectory](https://msdn.microsoft.com/en-us/library/system。diagnostics.processstartinfo.workingdirectory(v = vs.110).aspx) – bansi
yes如何执行这2个注释 –
应该是''tetml -m wordplus“+ inputfile;'< - 注意空格。另外请注意,您不需要拆分字符串并获取最后一部分以获取可使用[Path.GetFileName](https://msdn.microsoft.com/en-us/library/system.io.path。 getfilename(v = vs.110).aspx) – bansi