我的程序中有getRuntime().exec()调用;但是,其中两个调用无法工作:
public static final ROTCW = "xrandr -o left"
public static final CALCW1 = "xinput --set-prop 11 \"Evdev Axis Inversion\" 0 1"
public static final CALCW2 = "xinput --set-prop 11 \"Evdev Axes Swap\" 1";
public void actionPerformed(ActionEvent e)
{
try {
Runtime.getRuntime().exec(ROTCW);
Runtime.getRuntime().exec(CALCW1);
Runtime.getRuntime().exec(CALCW2);}
catch (IOException ioe){ ioe.printStackTrace();}
}});ROTCW绝对工作(屏幕旋转cw),但它不校准(CALCW)。在与我启动程序相同的终端选项卡中手动输入CALCWs不起作用,但将其输入新的终端选项卡/窗口确实有效。
为什么会发生这种情况,是什么解决了它?
发布于 2012-03-26 19:16:04
您可以直接在Java中实现&&逻辑:
public static final String
ROTCW = "xrandr -o left",
CALCW1[] = {"xinput", "--set-prop", "11", "\"Evdev Axis Inversion\"", "0", "1"},
CALCW2[] = {"xinput", "--set-prop", "11", "\"Evdev Axes Swap\"", "1"};
public void actionPerformed(ActionEvent e)
{
try {
Runtime.getRuntime().exec(ROTCW).waitFor();
Process p = Runtime.getRuntime().exec(CALCW1);
p.waitFor();
if( p.exitValue() != 0 ) Runtime.getRuntime().exec(CALCW2);
}
catch (IOException ioe){ ioe.printStackTrace();}
}});发布于 2012-03-26 18:59:37
尝试将shell添加到
public static final CALCW = "bash -c 'xinput --set-prop 11 \"Evdev Axis Inversion\" 0 1" +
" && xinput --set-prop 11 \"Evdev Axes Swap\" 1'"澄清&&是shell的语法,也是程序的另一个参数。
发布于 2016-09-15 15:06:52
这是个老问题,但我没有找到答案,所以我出版了一个。
您必须使用exec()的数组版本,并在命令的适当部分中没有引号:
CALCW1[] = {"xinput", "set-prop", "11", "Evdev Axis Inversion", "0", "1"}https://stackoverflow.com/questions/9877983
复制相似问题