0 Replies Latest reply: Apr 27, 2012 3:06 PM by 933787 RSS

    passing parameter from GET function to python script in Restful server

    933787
      Dear members,

      I have a small problem, in which i am struck for few days now.

      Here is my Get Restful code, in this i use Pathparam to pass parameter via the web-browser.

      @GET
      @Path("/instrumentlist/instrumentname/{name1}/{command}")
      @Consumes("text/plain")
      //@Override
      public Response Command(@PathParam("name1") String name1, @PathParam("command") String command)

      {       
      try {

      String [] env=null;
      String[]callAndArgs= {"python","command.py",name1,command};// passing two agruments to python file

      Process p = Runtime.getRuntime().exec(callAndArgs,env,
      new java.io.File("C:\\Users\\Balkishore\\Documents\\NetBeansProjects\\Testinstrument_Rest\\build\\web"));//executing the python file

      BufferedReader stdInput = new BufferedReader(new

      InputStreamReader(p.getInputStream()));//getting the output

      BufferedReader stdError = new BufferedReader(new

      InputStreamReader(p.getErrorStream()));//getting the error

      command_result = stdInput.readLine();//reading the output

      System.out.println(command_result);

      }
      catch (IOException e) {//catching the exception

      System.out.println("exception occured");

      e.printStackTrace();

      System.exit(-1);
      }
      return Response.status(200)
      .entity("command result : " + command_result)
      .build();//retruning the command response
      }
      }

      As it can be seen from above code i pass the parameter using PAthParam to the python file Command.py. But when i enter the parameter value (i.e) name1=*USB0::0x164E::0x13EC::TW00008555*; which is the id of my instrument connected and command=**IDN?*, which is SCPI command to get the name of the instrumnet, in the browser window i get an error: Command result NULL, but in reality i should get either 0 or 1.

      But am kinda confused if the values i am passing in the browser window is actually passed in String[]callAndArgs= {"python","command.py",name1,command}; or not?

      If not what i could do to pass this values?
      Is my code correct? or am i missing something in it?

      Any help would be very much appreciated. Thanks a ton in advance.!

      Cheers!

      Edited by: user5820746 on Apr 27, 2012 1:06 PM