werdnanoslen werdnanoslen - 1 year ago 85
Java Question

getRuntime().exec(<command>): <command> not working

I have getRuntime().exec() calls in my program; however, two of them will not work:

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 {
catch (IOException ioe){ ioe.printStackTrace();}

ROTCW definitely works (the screen rotates cw), but it does not calibrate (CALCW). Typing the CALCWs manually in the same terminal tab as the one I started the program with does not work, but typing it into a new terminal tab/window does work.

Why does this happen, and what fixes it?

Answer Source

You could implement the && logic directly in 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 {
        Process p = Runtime.getRuntime().exec(CALCW1);
        if( p.exitValue() != 0 ) Runtime.getRuntime().exec(CALCW2);
    catch (IOException ioe){ ioe.printStackTrace();}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download