我是新手,遇到点麻烦,向各位请教:
使用C#里面的process启动cmd命令行,在cmd中启动其他程序,该程序启动后不到10秒便会自动关闭,不知道是什么原因。以下是我写的代码: public void Login(string userID, string userPassWord, string projectName, string subprojectName, string path)
{ accountName = userID;
accoutPassword = userPassWord;
project = projectName;
subpro = subprojectName; // Create the directory if it does not exist.
DirectoryInfo pathName = new DirectoryInfo(path);
if (!pathName.Exists)
{
pathName.Create();
targetDirection = pathName.FullName + "\\";
}
else
{
targetDirection = pathName.FullName + "\\";
} string progremPath = @"cd /d C:\Program Files\eng\v2_2b2\bin";
string initial_cmd = " -user=" + accountName + " -pass=" + accoutPassword + " -proj=" + project + " -sub=" + subpro + " -def=" + targetDirection;
p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
p.Start();
p.StandardInput.WriteLine(progremPath);
p.StandardInput.WriteLine(initial_cmd);
if (!Check__Start())
{
MessageBox.Show(" cannot start!");
Process.GetCurrentProcess().Kill();
}
else
{
MessageBox.Show(" start!");
}
}
private bool Check_Start()
{
//check if the program has started
//search 10 times,5 seconds per time
//if not find, exit
int searching_times = 1;
do
{
foreach (Process thisproc in System.Diagnostics.Process.GetProcesses())
{
if (thisproc.ProcessName == "javaw")
{
return true;
}
}
Thread.Sleep(5000);
searching_times++;
}while (searching_times < 10);
return false;
}
使用C#里面的process启动cmd命令行,在cmd中启动其他程序,该程序启动后不到10秒便会自动关闭,不知道是什么原因。以下是我写的代码: public void Login(string userID, string userPassWord, string projectName, string subprojectName, string path)
{ accountName = userID;
accoutPassword = userPassWord;
project = projectName;
subpro = subprojectName; // Create the directory if it does not exist.
DirectoryInfo pathName = new DirectoryInfo(path);
if (!pathName.Exists)
{
pathName.Create();
targetDirection = pathName.FullName + "\\";
}
else
{
targetDirection = pathName.FullName + "\\";
} string progremPath = @"cd /d C:\Program Files\eng\v2_2b2\bin";
string initial_cmd = " -user=" + accountName + " -pass=" + accoutPassword + " -proj=" + project + " -sub=" + subpro + " -def=" + targetDirection;
p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
p.Start();
p.StandardInput.WriteLine(progremPath);
p.StandardInput.WriteLine(initial_cmd);
if (!Check__Start())
{
MessageBox.Show(" cannot start!");
Process.GetCurrentProcess().Kill();
}
else
{
MessageBox.Show(" start!");
}
}
private bool Check_Start()
{
//check if the program has started
//search 10 times,5 seconds per time
//if not find, exit
int searching_times = 1;
do
{
foreach (Process thisproc in System.Diagnostics.Process.GetProcesses())
{
if (thisproc.ProcessName == "javaw")
{
return true;
}
}
Thread.Sleep(5000);
searching_times++;
}while (searching_times < 10);
return false;
}
解决方案 »
- 业务问题
- 在winform的listview中,怎么让Id自动增长?
- 怎么得到一个url的地址?
- 串口控制MODEM拨号不能检测到载波的问题,请教高手
- 新手问个初级问题:建立c/s架构服务器端,是新建个windows服务还是控制台应用程序?
- Tcp传输到底会不会丢数据?给点建设性意见。
- ==================c# treeview中,如何知道我点的+是哪个node?===================
- 急求助,大神帮忙.连接执行oracle,报错
- dll里的委托的问题
- 提供三个学习dotnet的站点
- vs2008 发布部署依赖项的生成问题
- vb向C#一个textbox框中传递文本
砍了?