我正在尝试在我的程序后台的cmd中运行这些命令:
我不确定应该从哪里开始,但尝试过这个:
private void FileSelect_Click(object sender, EventArgs e)
{
string databaseDirectory = saveAndLoad.getFolderContentsFilename();
FilePath.Text = databaseDirectory;
}
private void xmlGenerator_Click(object sender, EventArgs e)
{
string file = FilePath.ToString();
var process = new Process();
var startInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Hidden,
FileName = "path to your script file..."
};
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
if (process.ExitCode == 0)
{
//success
}
else
{
//an error occured during script execution...
}
}
我的代码的总体目标是根据已提交给SVN的更改生成xml文件,需要运行的命令行应该创建一个xml文件。我想在程序的后台执行此操作,而不显示cmd。
任何帮助都会很棒。
谢谢
答案 0 :(得分:0)
您正在尝试运行位于startInfo.FileName
路径的文件中的程序,而不是您的脚本。将要执行的脚本保存到文件中,将脚本文件的路径传递给StartInfo
对象,启动进程并等待其执行:
var process = new Process();
var startInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Hidden,
FileName = "path to your script file..."
};
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
if (process.ExitCode == 0)
{
//success
}
else
{
//an error occured during script execution...
}