java - Script that's run from processing is not executing properly -


i have shell script creates text file contains current settings camera:

#!/bin/sh file="test.txt" [[ -f "$file" ]] && rm -f "$file"  var=$(gphoto2 --summary) echo "$var" >> "test.txt"    if [ $? -eq 0 ]     echo "successfully created file"     exit 0 else     echo "could not create file" >&2     exit 1 fi 

the script works think should when run terminal, when run following processing app text file created not contain of information camera:

import java.util.*; import java.io.*;  void setup() {     size(480, 120);     camsummary(); }  void draw() { } void camsummary() {     string commandtorun = "./ex2.sh";      file workingdir = new file("/users/loren/documents/rc/camsoft/");     string returnedvalues;    // value return results        try {         println("in try");         process p = runtime.getruntime().exec(commandtorun, null, workingdir);         int = p.waitfor();         if (i==0) {             bufferedreader stdinput = new bufferedreader(new inputstreamreader(p.getinputstream()));             while ( (returnedvalues = stdinput.readline ()) != null) {             println(returnedvalues);             }        } else{             println("i is:  " + i);         }    }    catch(throwable t) {        println(t);    } } 

eventually read of data directly script variables , use variables in processing.

could me sort out?

thank you,

loren

alternate script:

#!/bin/sh  set -x exec 2>&1  file="test.txt" [ -f "$file" ] && rm -f "$file"   # want store output of gphoto2 in variable # var=$(gphoto2 --summary) # problem 1: if path environment variable wrong (i.e. gphoto2 not accessible)? # problem 2: if gphoto2 outputs stderr? # it's better first to:  echo first if if ! type gphoto2 > /dev/null 2>&1;     echo "gphoto2 not found!" >&2     exit 1 fi  echo second if # why using var?... gphoto2 --summary > "$file" 2>&1 # if insert echo here, alter $? if [ $? -eq 0 ];     echo "successfully created file"     exit 0 else     echo "could not create file" >&2     exit 1 fi 

there several issues in shell script. let's correct , improve together.

#!/bin/sh  file="test.txt" [ -f "$file" ] && rm -f "$file"  # want store output of gphoto2 in variable # var=$(gphoto2 --summary) # problem 1: if path environment variable wrong (i.e. gphoto2 not accessible)? # problem 2: if gphoto2 outputs stderr? # it's better first to: if ! type gphoto2 > /dev/null 2>&1;     echo "gphoto2 not found!" >&2     exit 1 fi # why using var?... gphoto2 --summary > "$file" 2>&1 # if insert echo here, alter $? if [ $? -eq 0 ];     echo "successfully created file"     exit 0 else     echo "could not create file" >&2     exit 1 fi 

Comments