[英]java: getRuntime().exec() passing arguments to a Python program
I'm trying to pass run and pass arguments into a python program and am having trouble. 我试图将运行和参数传递给python程序,并且遇到了麻烦。 Here's what I'm doing now:
这是我现在正在做的事情:
String[] testCases=readIn("C:\\xampp\\htdocs\\development\\"+folder+"\\testCases.txt");
String arguements="";
for(int i=0; i<testCases.length; i++)
{
if(i==0)
{
arguements=testCases[i]+" ";
}
else
{
arguements=arguements+testCases[i]+" ";
}
command= new String[]{"C:\\Python27\\python.exe","C:\\xampp\\htdocs\\development\\"+fileName, arguements};
Process process=Runtime.getRuntime().exec(command);
I'm pretty sure I'm passing in the arguments correctly. 我很确定我正确地传递了参数。 Is there some way that I need to indicate that they are arguments that my Python code will talk in?
我是否需要通过某种方式表明它们是我的Python代码可以使用的参数?
You are indeed passing the arguments wrong. 您的说法确实是错误的。 You need to pass each argument as a string in the
command
array. 您需要在
command
数组中将每个参数作为字符串传递。 eg, 例如,
command = new String[arguments.length + 2];
command[0] = "C:\\Python27\\python.exe";
command[1] = "C:\\xampp\\htdocs\\development\\" + fileName;
System.arraycopy(arguments, 0, command, 2, arguments.length);
Try printing the final command that you get to the console and execute that in command line. 尝试打印到达控制台的最终命令,然后在命令行中执行该命令。 You will be able to dig down the exact error.
您将能够找到确切的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.