我有一个 shell 脚本,它接受一个参数并打印到文件 Logone.txt
:
name=$1
log_file="Logone.txt"
if [[ -n "$name" ]]; then
echo "$1" >> ${log_file}
else
echo "argument error"
fi
这在使用 GitBash 测试时有效。下面的示例以 666
作为参数。:
~/Documents/Documents/rt-wizard/source
bash pm2_StopStart.bash 666
我现在尝试在 Java 代码中使用 ProcessBuilder
做同样的事情。
try {
ProcessBuilder pb = new ProcessBuilder("bash", "-c", "pm2_StopStart.bash");
Process p = pb.start();
} catch (IOException e) {
System.out.println(e.getMessage());
}
这给出了一个错误:
<块引用>CreateProcess 错误=193,%1 不是有效的 Win32 应用程序
脚本 pm2_StopStart.bash
位于 ~/Documents/Documents/rt-wizard/source
并且程序也在同一目录中运行。