command line instructions and error codes

edited June 2017 in Questions about Code

Hey there, I'm looking for advice for I can't find a way through this

1 - Capture camera pic via processing (I know it is and how

2 - run the go program via command line in my sketch, in order to process the captured pic #1. Result is stored in folder on my harddrive.

3 - display the result as output of #2 and add a funny message.

Only problem is #2 : I've tried to add Runtime.getRuntime().exec with a shell script that would run a go program. Intructions are like this

    String batFile = "/Users/admin/Documents/Processing/Insultarium_ioRuntime/babash";

    //Pasted from : https:// forum.processing.org/one/topic/execute-terminal-commands-again.html
    String[] cmd_chmod = {"/bin/chmod", "+x", batFile}; 
    Process p1;
    Process p2;   

    try {
      p1 = Runtime.getRuntime().exec(cmd_chmod); //run shell cmd to make the shell file executable
      p2 = Runtime.getRuntime().exec(batFile); //run the shell file
      p2.waitFor();
      float error = p2.exitValue();
      println("Error = " + error);      
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
  }

The shell script actually works when standalone launch...

Error code returned is

Error = 1.0

Can someone tell me what it means ? Or any piece of advice would be much appreciated Thanks

Answers

  • please don't post duplicates

  • Right, sorry

  • run the command standalone. then type echo $?. that's the exit value. 1 normally indicates an error.

    koogs> echo "hello world" | grep "nothing"
    koogs> echo $?
    1
    koogs> echo "hello world" | grep "hello"
    hello world
    koogs> echo $?
    0
    
  • but, really, any shell script that you write can return anything

    what's in babash?

  • edited June 2017

    Hi Koogs, and thanks for your kind interest and help. babash is a simple script really, contains the following command line I'm using to run the go script, it has absolute path to script, parameters are image (input) and image (output), and numbers of shapes

    /Users/admin/Documents/Processing/Insultarium/primitive-master -i data/170628_164412.png -o data/outputcha2.png -n 100

    That line I can use to launch the go script with terminal, as I've put it in sketch folder... My guess is maybe Processing doesn't have acces to key value of GOPATH (environment variable).

  • edited June 2017

    the go script

    have you explained this anywhere?

    ** comment copied from other thread **

    alright, it's here:

    https://forum.processing.org/two/discussion/23085/use-command-line-instructions-in-sketch

    THIS IS WHY we try to keep all the information in one place and not start pointless duplicate threads.

    in the babash script try adding a 2>/tmp/errors to capture stderr, see if it prints anything. you could also call env to get it to print the environment if you think something is missing

  • I tried to &>filou.txt my script as you asked in parallel topic as closing it. Also printed the env list, GOPATH is okay, the value is now my sketch path. Babash still works under new GOPATH value.

    Err File is empty, Processing console shows results of println("Error = " + error); = 1.0

    Thanks for your sharing your time with me on this

  • did you mean &>filou.txt because it's usually 2>filou.txt (stream 1 is stdout, 2 is stderr)

  • edited July 2017

    I have tried them both &> and 2> actually using &>, stille it makes the same output : nothing in file and console error code 1.0

Sign In or Register to comment.