我的程序中有 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 确实有效(屏幕顺时针旋转),但它无法校准(CALCW)。在与我启动程序所用的终端选项卡相同的终端选项卡中手动键入 CALCW 不起作用,但将其键入新的终端选项卡/窗口却起作用。 p>
为什么会发生这种情况?如何解决?
最佳答案
您可以直接在 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();}
}});
关于java - getRuntime().exec(<命令>) : <command> not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9877983/