java - getRuntime().exec(<命令>) : <command> not working

标签 java runtime.exec xinput

我的程序中有 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/

相关文章:

java - 使用 jackson databind 将 JSON 反序列化为 Map<String,String>

java - 在 JFileChooser 中隐藏 "choosable file filter"小部件

Java - 在 rt.exec 调用 WinXP 32 位的 C++ 程序后,应用程序随机挂起

java - 通过 Runtime.exec() 执行管道 ps unix 命令时出现问题

c# - Windows UWP 中对 Xbox One 的 Controller 支持

macos - 将 XInput 调用转换为 MAC OS X 上的 DirectInput 调用(从 PS3 模拟 x360 Controller )

java - 使用特定版本的 JRE 执行 JAR 文件

java - 使用 JAXB 数据绑定(bind)的基于 CXF WSDL 的通用服务器

java - 如何以编程方式知道 Runtime.exec() 进程何时卡住?

google-chrome - 从触摸屏在 Chrome 中启用触摸事件