C# 写的Winform程序,程序中调用启动war服务。
本地测试是没有问题的,把程序拷贝到服务器运行。当启动服务时出现了异常,提示“系统找不到指定的路径”。
报错的代码很简单,就是找不出原因来。
private void startProcess(string id, string path, string warname)
{
try
{
string filepath = Path.Combine(path, warname);
this.updateMessageLabel.Text += "\r\n\t war文件路径:" + filepath;
if (!File.Exists(filepath))
{
//MessageBox.Show("文件不存在!\n" + filepath);
return;
}
Process process = new Process();
process.StartInfo.FileName = "java";
process.StartInfo.CreateNoWindow = false;
process.StartInfo.Arguments = "-jar " + filepath;
process.Start();//启动程序
int pid = process.Id;
//pid更新到datagridview中
for (int i = 0; i
{
if (nodelist[i].Id == id)
{
nodelist[i].Pid = pid + "";
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return;
}
}
其中第5行本人把war文件地址输出,地址是完全正确的。
本地和服务器都是64位系统。
有什么可能的原因导致这种问题呢?
解决方案
11
检查一下jdk的版本
11
你说的地址正确指什么? 地址格式没问题吗?
检查一下地址的路径是不是都存在
11
是不是 process.StartInfo.Arguments = “-jar ” + filepath; 没加空格啊
process.StartInfo.Arguments = ” -jar ” + filepath;//-jar 前面加空格试试
11
引用:
是不是 process.StartInfo.Arguments = “-jar ” + filepath; 没加空格啊
process.StartInfo.Arguments = ” -jar ” + filepath;//-jar 前面加空格试试
有可能是这个原因
11
把war包改名试试,别加”-“了
11
///
/// 执行DOS命令,返回DOS命令的输出
///
/// dos命令
/// 等待命令执行的时间(单位:毫秒),
/// 假如设定为0,则无限等待
/// 返回DOS命令的输出
public static string Execute(string command, int seconds)
{
string output = “”; //输出字符串
if (command != null && !command.Equals(“”))
{
Process process = new Process();//创建进程对象
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = “cmd.exe”;//设定需要执行的命令
startInfo.Arguments = “/C ” + command;//“/C”表示执行完命令后马上退出
startInfo.UseShellExecute = false;//不使用系统外壳程序启动
startInfo.RedirectStandardInput = false;//不重定向输入
startInfo.RedirectStandardOutput = true; //重定向输出
startInfo.CreateNoWindow = true;//不创建窗口
startInfo.Verb = “runas /user:Administrator cmd”;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.CreateNoWindow = false; //显示
process.StartInfo = startInfo;
try
{
if (process.Start())//开始进程
{
if (seconds == 0)
{
process.WaitForExit();//这里无限等待进程结束
}
else
{
process.WaitForExit(seconds); //等待进程结束,等待时间为指定的毫秒
}
output = process.StandardOutput.ReadToEnd();//读取进程的输出
}
}
catch
{
}
finally
{
if (process != null)
process.Close();
}
}
return output;
}
本人觉得你得执行cmd.exe,要不然不会寻找环境变量信息的
CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明java -jar xxxx.war 找不到系统文件路径!