Interact with linux, send command to shell

edited September 2015 in Questions about Code

Hello everyone, I' new on Processing I have a Python background and I need to find a function to execute a command on Shell.

For example I build a GUI with some buttons and each button send a command to the system OS.

Is that possible?

Thanks for help

Answers

  • edited September 2015

    https://processing.org/reference/open_.html doesnt work :(


    void mousePressed() {
     String[] params = {"rdesktop 10.5.6.6" };
     exec(params);  //with open() the output is -- The function "Open(string[])" does not exist. --
    }
    

    My output is

    java.io.IOException: Cannot run program "rdesktop 10.5.6.6": error=2, File or directory does not exist
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
        at java.lang.Runtime.exec(Runtime.java:620)
        at java.lang.Runtime.exec(Runtime.java:485)
        at processing.core.PApplet.exec(PApplet.java:3472)
        at sketch_150903a.mousePressed(sketch_150903a.java:27)
        at processing.core.PApplet.mousePressed(PApplet.java:2750)
        at processing.core.PApplet.handleMouseEvent(PApplet.java:2683)
        at processing.core.PApplet.dequeueEvents(PApplet.java:2601)
        at processing.core.PApplet.handleDraw(PApplet.java:2412)
        at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1499)
        at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:312)
    Caused by: java.io.IOException: error=2, File or directory does not exist
        at java.lang.UNIXProcess.forkAndExec(Native Method)
        at java.lang.UNIXProcess.<init>(UNIXProcess.java:248)
        at java.lang.ProcessImpl.start(ProcessImpl.java:134)
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
        ... 10 more
    

    Thanks

  • This is the reference for exec():
    http://docs.oracle.com/javase/8/docs/api/java/lang/Runtime.html#exec-java.lang.String:A-

    It's of extreme importance mentioning which Processing series/version being used!
    Since there's a huge chasm among them! [-(

Sign In or Register to comment.