Executing unix script within java and getting the return value

Hi
I am executing a unix script from within java which will return me a value. Is there a way I get this value and use it inside my java code without doing this:
BufferedReader in = new BufferedReader( new InputStreamReader( ls_proc.getInputStream() ));
//readLine reads in one line of text
int k = 1, i = 0;
while (( ls_str = in.readLine()) != null)
--kirk123                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

I was hoping to get what I want in one or two line codes.
--kirk123                                                                                                                                                                                           

Similar Messages

  • How to call an Oracle Procedure and get a return value in Php

    Hi Everyone,
    Has anyone tried calling an Oracle procedure from Php using the ora functions and getting the return value ? I need to use the ora funtions (no oci)because of compatibility and oracle 7.x as the database.
    The reason why I post this here is because the ora_exec funtion is returning FALSE but the error code displayes is good. Is this a bug in the ora_exec funtion ?
    My code after the connection call is as follows:
    $cur = ora_open($this->conn);
    ora_commitoff($this->conn);
    $requestid = '144937';
    echo $requestid;
    $rc = ora_parse($cur, "begin p_ins_gsdata2
    (:requestid, :returnval); end;");
    if ($rc == true) {
    echo " Parse was successful ";
    $rc2 = ora_bind ($cur, "requestid", ":requestid", 32, 1);
    if ($rc2 == true) echo " Requestid Bind Successful ";
    $rc3 = ora_bind ($cur, "returnval", ":returnval", 32, 2);
    if ($rc3 == true) echo " Returnval Bind Successful ";
    $returnval = "0";
    $rc4 = ora_exec($cur);
    echo " Result = ".$returnval." ";
    if ($rc4 == false) {
    echo " Exec Returned FALSE ";
    echo " Error = ".ora_error($cur);
    echo " ";
    echo "ErrorCode = ".ora_errorcode($cur);
    echo "Error Executing";
    ora_close ($cur);
    The Oracle procedure has a select count from a table and it returns the number of records in that table. It's defined as:
    CREATE OR REPLACE procedure p_ins_gsdata2 (
    p_requestid IN varchar2 default null,
    p_retcode OUT varchar2)
    as
    BEGIN
    SELECT COUNT (*) INTO p_retcode
    FROM S_GSMRY_DATA_SURVEY
    WHERE request_id = p_requestid ;
    COMMIT;
    RETURN;
    END;
    Nothing much there. I want to do an insert into a table,
    from the procedure later, but I figured that I start with a select count since it's simpler.
    When I ran the Php code, I get the following:
    144937
    Parse was successful
    Requestid Bind Successful
    Returnval Bind Successful
    Result = 0
    Exec Returned FALSE
    Error = ORA-00000: normal, successful completion -- while
    processing OCI function OBNDRA
    ErrorCode = 0
    Error Executing
    I listed the messages on separate lines for clarity. I don't understand why it parses and binds o.k. but the exec returns false.
    Thanks again in advance for your help. Have a great day.
    Regards,
    Rudi

    retcode=`echo $?`is a bit convoluted. Just use:
    retcode=$?I see no EOF line terminating your input. Your flavour of Unix might not like that - it might ignore the command, though I'd be surprised (AIX doesn't).
    replace the EXEC line with :
    select 'hello' from dual;
    and see if you get some output - then you know if sqlplus commands are being called from your script. You didn't mentioned whether you see the banner for sqlplus. Copy/paste the output that you get, it will give us much more of an idea.

  • How execute Unix script from java?

    Can I execute Unix script from java?

    Yes. Using ProcessBuilder. And read [When Runtime.exec() wont|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html]. It's old, but pretty much all of it is still true.

  • Remote Object - not able to get the returned value from java method

         Hi ,
    I am developing one sample flex aplication that connects to the java code and displays the returned value from the
    java method in flex client. Here I am able to invoke the java method but not able to collect the returned value.
    lastResult is giving null .  I am able to see the sysout messages in server console.
    I am using flex 3.2 and blazeds server  and java 1.5
    Here is the code what I have written.
    <?xml version="1.0" encoding="utf-8"?><mx:WindowedApplication  xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#FFFFFF" initialize="initApp()">
     <mx:Script><![CDATA[
    import mx.controls.Alert; 
    import mx.binding.utils.ChangeWatcher; 
    import mx.rpc.events.ResultEvent; 
    import mx.messaging.*; 
    import mx.messaging.channels.* 
    public function initApp():void { 
         var cs:ChannelSet = new ChannelSet(); 
         var customChannel:Channel = new AMFChannel("my-amf", "http://localhost:8400/blazeds/messagebroker/amf");     cs.addChannel(customChannel);
         remoteObj.channelSet = cs;
    public function writeToConsole():void {      remoteObj.writeToConsole(
    "hello from Flash client");
          var returnedVal:String = remoteObj.setName().lastResult;     Alert.show(returnedVal);
    //[Bindable] 
    // private var returnedVal:String; 
    ]]>
    </mx:Script>
    <mx:RemoteObject id="remoteObj" destination="sro" /> 
    <mx:Form width="437" height="281">
     <mx:FormItem>  
    </mx:FormItem>  
    <mx:Button label="Write To Server Console" click="writeToConsole()"/>
     </mx:Form>
     </mx:WindowedApplication>
    Java code
    public  
         public SimpleRemoteObject(){  
              super();     }
      class SimpleRemoteObject { 
         public void writeToConsole(String msg) {          System.out.println("SimpleRemoteObject.write: " + msg);     }
         public String setName(){          System.
    out.println("Name changed in Java"); 
              return "Name changed in Java";
    And I have configured destination in  remote-config.xml
    <destination id="sro">
       <properties>    
        <source>SimpleRemoteObject</source>
        <scope>application</scope>
       </properties>
      </destination>
    Please help me .

    You are not able to get the returned value because if you see the Remote object help you will realise you have to use result="resultfn()" and fault = "faultfn()"
    In this you define what you wish to do.
    More importantly in the remote object you need to define which method you wish to call using the method class like this
    <mx:RemoteObject id="remoteObj" destination="sro" result="r1" fault="f1"  >
         <Method name="javaMethodName" result="r2" fault="f2"/>
    <mx:RemoteObject>
    r2 is the function where you get the result back from java and can use it to send the alert.

  • Get the return value of an RFC function / BAPI

    Hello,
    I'm a Web Dynpro Java beginner and I try to get the return value (domain: NUMC6) of an RFC function without success.
    Here is what I do, could you please tell me what is wrong?
    First, here is my context:
    Context
    |
    |---- ZMy_Bapi
         |
         |---- MyOutputResult
         |     |
         |     |---- MyReturnValue
         |
         |---- MyInput
    My model:
    MyModel
    |
    |---- ZMy_Bapi_Input
         |
         |---- Output
         |     |
         |     |---- ZMy_Bapi_Output
         |          |
         |          |---- Return_Value
         |
         |---- Input_Value
    The mapping between them:
    - MyInput is mapped to Input_Value
    - MyReturnValue is mapped to Return_Value
    And my code:
    ZMy_Bapi_Input bapiInput = new ZMy_Bapi_Input();
    wdContext.nodeZMy_Bapi().bind(bapiInput);
    bapiInput.setInput_Value("A value");
    executeZMy_Bapi();
    ZMy_Bapi_Output bapiOutput = new ZMy_Bapi_Output();
    wdContext.nodeMyOutputResult().bind(bapiOutput);
    IMyOutputResultElement outputElement = wdContext.nodeMyOutputResult().currentMyOutputResultElement();
    String result = outputElement.getMyReturnValue();
    Finally, here is the code of the executeZMy_Bapi() function:
    try {
         wdContext.currentZMy_BapiElement().modelObject().execute();
         wdContext.nodeMyOutputResult().invalidate();
    } catch (Exception ex) {
         ex.printStackTrace();
    My problem is that "result" keeps being empty
    Thanks in advance for your help!

    It still doesn't work, I'm gonna turn crazy!
    But there is one good point: I get the method you mentioned: getZMy_Bapi_OutputElementAt and getMyReturnValue without casting, just as you said first.
    Here are the updated context, model, mapping and code.
    Context:
    MyContext
    |
    |---- ZMy_Bapi
         |
         |---- MyOutputResult
         |     |
         |     |---- ZMy_Bapi_Output
         |          |
         |          |---- MyReturnValue
         |
         |---- MyInput
    Model:
    MyModel
    |
    |---- ZMy_Bapi_Input
    |     |
    |     |---- Output
    |     |     |
    |     |     |---- ZMy_Bapi_Output
    |     |          |
    |     |          |---- Return_Value
    |     |
    |     |---- Input_Value
    |
    |
    |---- ZMy_Bapi_Output
         |
         |---- Return_Value
    Mapping
    ZMy_Bapi     --> ZMy_Bapi_Input
    MyOutputResult     --> Output
    ZMy_Bapi_Output     --> ZMy_Bapi_Output
    MyReturnValue     --> Return_Value
    MyInput          --> Input_Value
    Code
    ZMy_Bapi_Input bapiInput = new ZMy_Bapi_Input();
    wdContext.nodeZMy_Bapi().bind(bapiInput);
    bapiInput.setInput_Value("A value");
    executeZMy_Bapi();
    ZMy_Bapi_Output bapiOutput = new ZMy_Bapi_Output();
    wdContext.nodeMyOutputResult().bind(bapiOutput);
    String result = "";
    for (int i = 0; i < wdContext.nodeZMy_Bapi_Output().size(); i++) {
         IZMy_Bapi_OutputElement resultElem = wdContext.nodeZMy_Bapi_Output().getZMy_Bapi_OutputElementAt(i);
         if (resultElem.getMyReturnValue() != "" && resultElem.getMyReturnValue() != null) {
              result = resultElem.getMyReturnValue();
    Edited by: Franis Pignon on Oct 17, 2008 11:16 PM

  • Call C# method from javascript in WebView and retrieve the return value

    The issue I am facing is the following :
    I want to call a C# method from the javascript in my WebView and get the result of this call in my javascript.
    In an WPF Desktop application, it would not be an issue because a WebBrowser
    (the equivalent of a webView) has a property ObjectForScripting to which we can assign a C# object containg the methods we want to call from the javascript.
    In an Windows Store Application, it is slightly different because the WebView
    only contains an event ScriptNotify to which we can subscribe like in the example below :
    void MainPage_Loaded(object sender, RoutedEventArgs e)
    this.webView.ScriptNotify += webView_ScriptNotify;
    When the event ScriptNotify is raised by calling window.external.notify(parameter), the method webView_ScriptNotify is called with the parameter sent by the javascript :
    function CallCSharp() {
    var returnValue;
    window.external.notify(parameter);
    return returnValue;
    private async void webView_ScriptNotify(object sender, NotifyEventArgs e)
    var parameter = e.Value;
    var result = DoSomerthing(parameter);
    The issue is that the javascript only raise the event and doesn't wait for a return value or even for the end of the execution of webView_ScriptNotify().
    A solution to this issue would be call a javascript function from the webView_ScriptNotify() to store the return value in a variable in the javascript and retrieve it after.
    private async void webView_ScriptNotify(object sender, NotifyEventArgs e)
    var parameter = e.Value;
    var result = ReturnResult();
    await this.webView.InvokeScriptAsync("CSharpCallResult", new string[] { result });
    var result;
    function CallCSharp() {
    window.external.notify(parameter);
    return result;
    function CSharpCallResult(parameter){
    result = parameter;
    However this does not work correctly because the call to the CSharpResult function from the C# happens after the javascript has finished to execute the CallCSharp function. Indeed the
    window.external.notify does not wait for the C# to finish to execute.
    Do you have any solution to solve this issue ? It is quite strange that in a Window Store App it is not possible to get the return value of a call to a C# method from the javascript whereas it is not an issue in a WPF application.

    I am not very familiar with the completion pattern and I could not find many things about it on Google, what is the principle? Unfortunately your solution of splitting my JS function does not work in my case. In my example my  CallCSharp
    function is called by another function which provides the parameter and needs the return value to directly use it. This function which called
    CallCSharp will always execute before an InvokeScriptAsync call a second function. Furthermore, the content of my WebView is used in a cross platforms context so actually my
    CallCSharp function more look like the code below.
    function CallCSharp() {
    if (isAndroid()) {
    //mechanism to call C# method from js in Android
    //return the result of call to C# method
    } else if (isWindowsStoreApp()) {
    window.external.notify(parameter);
    // should return the result of call to C# method
    } else {
    In android, the mechanism in the webView allows to return the value of the call to a C# method, in a WPF application also. But I can't figure why for a Windows Store App we don't have this possibility.

  • LiveCycle DS , can't get the return value of fill( arg) from Assembler class

    Hi all!
    I'm a have small problem , can any one help me? Please
    I make a project which very similar to Product project(in
    example).
    1) Have Assembler class: I work correctly
    package flex.samples.stock;
    import java.util.List;
    import java.util.Collection;
    import java.util.Map;
    import flex.data.DataSyncException;
    import flex.data.assemblers.AbstractAssembler;
    public class StockAssembler extends AbstractAssembler {
    public Collection fill(List fillArgs) {
    StockService service = new StockService();
    System.out.print(fillArgs.size());
    return service.getStocks();
    public Object getItem(Map identity) {
    StockService service = new StockService();
    return service.getStock(((Integer)
    identity.get("StockId")).intValue());
    public void createItem(Object item) {
    StockService service = new StockService();
    service.create((Stock) item);
    public void updateItem(Object newVersion, Object
    prevVersion, List changes) {
    StockService service = new StockService();
    boolean success = service.update((Stock) newVersion);
    if (!success) {
    int stockId = ((Stock) newVersion).getStockId();
    throw new DataSyncException(service.getStock(stockId),
    changes);
    public void deleteItem(Object item) {
    StockService service = new StockService();
    boolean success = service.delete((Stock) item);
    if (!success) {
    int stockId = ((Stock) item).getStockId();
    throw new DataSyncException(service.getStock(stockId),
    null);
    some require class is ok.
    2) I configure in data-management-config.xml
    <destination id="stockinventory">
    <adapter ref="java-dao" />
    <properties>
    <source>flex.samples.stock.StockAssembler</source>
    <scope>application</scope>
    <metadata>
    <identity property="StockId"/>
    </metadata>
    <network>
    <session-timeout>20</session-timeout>
    <paging enabled="false" pageSize="10" />
    <throttle-inbound policy="ERROR" max-frequency="500"/>
    <throttle-outbound policy="REPLACE"
    max-frequency="500"/>
    </network>
    </properties>
    </destination>
    3) My client app:
    I use :
    <mx:ArrayCollection id="stocks"/>
    <mx:DataService id="ds" destination="stockinventory"/>
    ds.fill(stocks); --> Problem here
    When I run this app, The StockAssembler on the server work
    correctly (i use printout to debug) . But variable stocks can't get
    the return value,it is a empty list.
    Please help me!

    Hi,                                                             
    The executeQueryAsync method is “asynchronous, which means that the code will continue to be executed without waiting for the server to
    respond”.
    From the error message “The collection has not been initialized”, which suggests that the object in use hadn’t been initialized after the execution of the executeQueryAsync method.
    I suggest you debug the code in browser to see which line of code will throw this error, then you can reorganize the logic of the code to avoid using the uninitialized object.
    A documentation from MSDN about Using the F12 Developer Tools to Debug JavaScript Errors
    for your reference:
    http://msdn.microsoft.com/en-us/library/ie/gg699336(v=vs.85).aspx
    Best regards
    Patrick Liang
    TechNet Community Support

  • How to get the return values from a web page

    Hi all :
       how to get the return values from a web page ?  I mean how pass values betwen webflow and web page ?
    thank you very much
    Edited by: jingying Sony on Apr 15, 2010 6:15 AM
    Edited by: jingying Sony on Apr 15, 2010 6:18 AM

    Hi,
    What kind of web page do you have? Do you have possibility to for example make RFCs? Then you could trigger events (with parameters that could "return" the values) and the workflow could react to those events. For example your task can have terminating events.
    Regards,
    Karri

  • Not getting the return value of a program though it has no  errors

    public static String giroReturnFileDate(String strType)throws IOException{
              try{
                   SimpleDateFormat getFormatDate = new SimpleDateFormat("yyMM");
                   Date date = new Date();
                   String str = getFormatDate.format(date);
                   System.out.println("Current Date is : "+ str);
                   System.out.println("Fetching the Giro file now");
                   if(strType.equalsIgnoreCase("WPD") || strType.equalsIgnoreCase("ISTD")) {
                   FileReader inputFileReader = new FileReader("giro2itcs_"+strType+".txt");
                   ArrayList list = new ArrayList();
                   ArrayList list1 = new ArrayList();
                   System.out.println("Reading the file");
                   BufferedReader inputStream = new BufferedReader(inputFileReader);
                   String inLine = null;
                   String str1 = null;
                   while((inLine = inputStream.readLine()) != null && inLine.length() < 2)
                        list.add(inLine);
                   System.out.println("Control Record for giro2itcs_"+strType+"is:"+ inLine);
                   inputFileReader.close();
                   inputStream.close();
                   for (int i=0; i<inLine.length(); i++ )
                        str1 = inLine.substring(19,23);
                   System.out.println("date of the transaction is:"+str1);
                   if (str .equals(str1)){
                        System.out.println("giro2itcs_"+strType+".txt file is created today");
                        return "true";
                   else{
                        System.out.println("giro2itcs_"+strType+".txt file is not created today");
                        return "false";
                   }// end of if
                   return "test";
              }// end of try
              catch(Exception e) {
              System.out.println("The Exception is ::::::::::::::"+e);
    return "one";
    }//end of giroReturnFileDate(...) method
    }//end of of the class
    main method is seperate. this program compiles fine but am not getting the return value for this. none of the return values. plzzz help me.

    can you send me the code complete one ...
    i will debug and solve the problem
    [email protected]
    By publishing your email address you are likely to get loads of spam.

  • Select_list_from_lov, cant get the returning value

    Hi
    I try to use a apex_item.select_list_from_lov in a wizard. The LOV that I have is a dynamic list.
    everything works fine, only I cant get the return value of the selected items.
    multi select list
    htp.p(apex_item.SELECT_LIST_FROM_LOV
    ( 2,
    'MOS_ROL_OMSCHRIJVING',
    ' MULTIPLE HEIGHT=5',
    'NO',
    null,
    null,
    null,
    null,
    'NO')
    trying to see what the return values are, but got nothing.
    :p12_test := :f02;
    (p12_test is a textfield)
    any assistance would be greatly appreciated.
    Thanks
    using apex 4.0.

    >
    trying to see what the return values are, but got nothing.
    :p12_test := :f02;
    (p12_test is a textfield)
    >
    f02 is an associative array. See Referencing Arrays in the APEX API Reference for information on how to access values of items created using apex_item methods.

  • Execute UNIX  script from java not working

    Hi
    I am having difficulty running my java program to execute UNIX script on a Windows box. Here is my code.
    public boolean executeScript() {
              try {
                   String testScript= "WEB-INF/scripts/test.sh";
                   File file = new File(copyToQaScript);
                   System.out.println(file.getAbsolutePath());
                   Process proc = Runtime.getRuntime().exec(file.getAbsolutePath());
              } catch (IOException ioe) {
                   ioe.printStackTrace();
                   logger.error(ioe);
              } catch (RuntimeException re) {
                   re.printStackTrace();
                   logger.error(re);
              } catch (Exception e) {
                   e.printStackTrace();
                   logger.error(e);
              return true;
         }When I execute this method, I am getting IOException as below.
    java.io.IOException: CreateProcess: C:\tomcat-5.0.28\webapps\myProject\WEB-INF\scripts\test.sh error=193
    Can anyone help me? Thanks.

    kminkeller wrote:
    Yes I have Cygwin installed. I am quite aware of that thanks Sabre.Then you need something like
          String[] command = {"bash","/home/sabre/bin/fred.sh"};
            Process p = Runtime.getRuntime().exec(command);
      if the executabe directory (/home/sabre/bin in my case) is not on the PATH or
          String[] command = {"bash","fred.sh"};
            Process p = Runtime.getRuntime().exec(command);
      if it is.

  • Calling the DTExec from Perl Script and need to get the Return Value (Sucess or Failure)

    I am able to execute the SSIS Package from Perl Script using DTExec. But i need to get the return code of the SSIS Execution. Is their any option available to get the Success or Failure information from Perl ?

    Exit codes returned from dtexec utility             
    When a package runs, dtexec can return an exit code. The exit code is used to populate the ERRORLEVEL variable, the value of which can then be tested in conditional statements or branching logic within a batch file. The following table lists
    the values that the dtexec utility can set when exiting.
    http://technet.microsoft.com/en-us/library/hh231187.aspx
    There's a wrinkle if the package is running in the SSIS Catalog:
    http://www.mattmasson.com/2012/02/exit-codes-dtexec-and-ssis-catalog/
    David
    David http://blogs.msdn.com/b/dbrowne/

  • How to set the value of an LOV in CO prgramatically and get the Pkey value?

    Hi,
    I need to set a value to a LOV, say ItemLOV in a page through CO and get the Primaykey that LOV will return. How can I achieve this?
    Req:
    1. Set the Item_Name, say 'DELL_1618' so that the page displays this in the LOV.
    2. Fetch the PK value returned by LOV in the backend into a VO attribute say Item_ID, '100009881'.
    Thanks,
    Santosh.

    Hi Santosh,
    Sorry, I replied for General LOV Scenario, but want to set it programatically right,
    You need to execute your LOV query in Controller for Item 'DELL_1618' using prepared statement, get the value for both dispaly value and Id and set it to LOV and FormVlaue Item in PR of controller.
    Regards,
    Reetesh Sharma

  • How to sample an analog signal, simulated on labview and get the sample values.

    My project involves this particular detail where i have to sample a simulated sine wave and get the samples and compare them so as to select a particular length for hanning window.Then it also requires me to experiment with the window size so as to get more efficient data out of the sampled signals. please help me with the sampling part and guide me as to how to perform a hanning window operation on the sampled signal. I have directly used the spectral analysis tool which involves getting a FFT spectrum by a default hanning window setting. But since i have to experiment with the window size and variations, guide me with the sampling part and applying a separate hanning window. Thank you.

    bhardoo wrote:
    My project involves this particular detail where i have to sample a simulated sine wave and get the samples and compare them so as to select a particular length for hanning window.Then it also requires me to experiment with the window size so as to get more efficient data out of the sampled signals. please help me with the sampling part and guide me as to how to perform a hanning window operation on the sampled signal. I have directly used the spectral analysis tool which involves getting a FFT spectrum by a default hanning window setting. But since i have to experiment with the window size and variations, guide me with the sampling part and applying a separate hanning window. Thank you.
    What do you mean by i have to sample a simulated sine wave?
    the sine generator will provide you with a waveform (or an array of values you can use), there are basic  vis to do all this, rigth click on the vi and select help to get detailed information.
    Post your vi if you have trouble with details.
    How much do you know about LabVIEW and signal theorie?
    Greetings from Germany
    Henrik
    LV since v3.1
    “ground” is a convenient fantasy
    '˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'

  • How to get the returned value from Functions with Callable statement?

    I was glad to find that stored procedures can be invoke with Java class code by the object of Callable statement like :
    String stmt = "BEGIN departments_pkg.do_select(?,?,?); END;";
    and getting the output variables by
    populateAttribute(DEPARTMENTNAME,st.getString(2),true,false);
    But i would like to get values returned from FUNCTION other than stored procedure, how can i achieve it? Thanks a lot!

    Here is  my code
    PROCESS BEFORE OUTPUT.
    MODULE STATUS_1202.
      MODULE subscreen_find.
      CALL SUBSCREEN SUBSEARCH INCLUDING sy-cprog dynnr.
    PROCESS AFTER INPUT.
      MODULE USER_COMMAND_1202.
      CALL SUBSCREEN SUBSEARCH.
    MODULE subscreen_find.
      case sy-ucomm.
        when 'SELECTED'.             "fcode
          case 'ZSKILL_SEARCH'.     "data element
            when '01'.                       " value range
              dynnr = 0110.
            when '02'.
              dynnr = 0111.
          endcase.
      endcase.
    ENDMODULE.
    kindly tell me what is wrong
    Edited by: Raji Thomas on Feb 8, 2010 10:20 AM

Maybe you are looking for