How to invoke from UNIX script and pass back return code?

Though I am an experienced developer, I am new to java. I created a class containing a single method. I have performed my testing by running the class class.method from the command line in a UNIX (Solaris) environment. Now, I would like to have the class.method invoked from a UNIX shell script, and to return a success/failure indicator from the method, to the UNIX script. I modified the method to make it return char, rather than being defined as void. Within the class and method, I declared and initialized a char variable. I added a finally clause which contains a single return statement, returning the char return code variable. Within my UNIX script, I invoke the class/method as follows:
return_code = java myClass
This does not seem to be invoking the method however. Can someone please tell me what I am doing wrong? Or is more information needed in order for someone to help me out.
Please let me know.
Thanks.
Brad

stdunbar,
Using your suggestion of System.exit(retVal); seems to allow the java method to be performed successfully (Thank You). But I am still having a problem with the value being recognized by the shell script.
In my script, I'm doing the following:
java MyClass inputparameter > return_code
export return_code
echo $return_code
But return_code does not seem to contain a value. Just before the System.exit(retVal); I added System.out.println("return code = " + retVal ); and I can see that retVal. When I run the java method outside of the UNIX shell script, I can see that retVal does indeed contain a value. So I think my problem might actually be the code in the UNIX script.
Thanks again.
Brad

Similar Messages

  • How to read from input file and pass to script

     How can I get rid of the hard coded PATH statement and feed script based upon text file input.
       Input is contained in a file..
    'C:\cntprocess\   called sistemfolder.txt that has 2 fields folder
    then shortname.
    example:
     C:\cntprocess\REW1___1~Rew1
     C:\cntprocess\REW2___1~Rew2
     I want the first part in each record passed to script for processing
    C:\cntprocess\REW1___1
    C:\cntprocess\REW2___1
    Pass those values to this Script: I want values from above passed to the $Path
    $path='C:\Sistemi\'
    get-childitem -path $path *.spx | % {
    " Starting File Process....." >> $path\sistem.log
    $PDate = get-date
    $date = get-date -uformat "_%d_%m_%Y_%H%M%S.bak"
    #"Set backup date to $date" >> $path\sistem.log
    $newname=($_.fullname -replace ".spx",$date)
    $file = [System.IO.Path]::GetFileNameWithoutExtension($_.fullname)
    "File backup name is $newname" >> $path\sistem.log
    Rename-Item $_.fullname $newname
    "Renamed file to $newname" >> $path\sistem.log
    $lines = get-content $newname
    foreach ($line in $lines)
    $line + " " + [System.IO.Path]::GetFileNameWithoutExtension($_.fullname) | Out-File "$path\sistem.csv" -append
    Write-Host $_.fullname
    "Files Processed on $PDate are $newname " >> $path\sistem.log
    Thanks.

    OK, I was mistaken a bit on what I originally told you. After you run the command of
    $myFile = Import-Csv -Delimiter '~' -Path $path -Header Path, ShortName
    $myFile is actually an array of PSCustomObjects, so you cannot access it like $myFile.Path, you will actually have to loop through the $myFile first, so try changing your script to be the following and see if that helps any
    param
    [string]$path
    $myFiles = Import-Csv -Delimiter '~' -Path $path -Header Path, ShortName
    # Then you can call it like so
    $myFiles.Path #Returns just the path
    $myFiles.ShortName # Returns the shortname
    $path='C:\AreaSistemi1\'
    foreach ($myFile in $myFiles)
    get-childitem -path $myFile.Path *.spx | % {
    " Starting File Process....." >> $myFile.Pathsistem.log
    $PDate = get-date
    $date = get-date -uformat "_%d_%m_%Y_%H%M%S.bak"
    #"Set backup date to $date" >> $path\sistem.log
    $newname=($_.fullname -replace ".spx",$date)
    $file = [System.IO.Path]::GetFileNameWithoutExtension($_.fullname)
    "File backup name is $newname" >> $myFile.Pathsistem.log
    Rename-Item $_.fullname $newname
    "Renamed file to $newname" >> $myFile.Pathsistem.log
    $lines = get-content $newname
    foreach ($line in $lines)
    $line + " " + $myFile.ShortName | Out-File "$path\sistem.csv" -append
    Write-Host $_.fullname
    "Files Processed on $PDate are $newname " >> $path\sistem.log
    Also looking at your script, you said your text file contained the format of <filePath>~<shortname> but I see you doing a $myFile.Pathisstem.log, where does the Pathisstem.log come from?
    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.
    Don't Retire Technet

  • Tcl proc with input argument run from UNIX script...how

    Environment:
    OWB 10g Client on Windows XP Professional
    Repository - 9.2.0.4 on UNIX (AIX 5.2)
    Target - 9.2.0.4 on UNIX (AIX 5.2)
    I need a little tcl advice, please!
    I have a tcl script (proc, I guess) that takes one argument, in this case a mapping name.
    I would like to execute this tcl script from a UNIX shell script and pass the name of the mapping as an argument to the UNIX shell script. Something like:
    OMBPlus.sh omb_deploy.tcl $1
    where omb_deploy.tcl is the script that has all the OMBPlus commands in it to create the deployment plan and execute it.
    I'd like to pass the mapping name as a command line argument to the UNIX shell script but it doesn't like it.
    When I execute the script as above, I don't see any output and the mapping does not get deployed.
    So, I need a little help on two (2) issues:
    1- How do I generate a log file of the output of the tcl script?
    2- How do I pass the mapping name as an argument to the UNIX shell script?
    For #1 I have tried using the 'open logfilename w' at the top of the tcl script but it produces no output.
    I saw another example from this forum where the author used a 'putslog' command in the script. I can't find any documentation on that command, what does it do?
    That same script set a global OMBLOG variable at the top of the script and used the 'putslog' command in the body.
    Is OMBLOG some special reserved word for logging? I couldn't find anything on it.
    I'm trying to learn tcl but struggling to put all the tcl stuff together with all the OMBPlus stuff and make it all work is getting the best of me.
    Any assistance, with examples (I learn best from them), is greatly appreciated.
    Gary

    Well duh!
    I ended up just logging everything from the UNIX shell script and letting the tcl script write everything to stdout.
    I also finally found the $argv parameter and have used that to pick up the name of the mapping being passed to OMBPlus.
    It seems to be working so far.
    Gary

  • How can i run unix script from my apex page

    how can i run unix script from my apex page and take the output of unix script as a hidden variable and display it on the report region of that page

    I had a requirement to run a Fortran program against some data that woudl be extracted from the database after the user set up their filtering criteria and made some additional input. SInce the program was to complex to conver to PL/SQL, we decided to try and invoke it from Apex. This is how I did it.
    1. I followed the steps in Tim Archer's excellent article "Oracle External Procedure to Run Host Commands" (http://www.timarcher.com/?q=node/9). If the link does nto work, google the article's title.
    Using this steps I created a function which accepts any OS command, including calling my own shell scripts, and runs them. I called my PL/SQL function "shell" instead of "USF_RUN_HOST_CMD " as Tim did in his example (step 9).
    2. In Apex,
    a. I created a button to run my shell command. (I named it P2_RUN_SHELL)
    b. I created a PL/SQL process whose source looks as follows:
    shell('/home/ackness/scripts/cr_xcf_file.sh > /tmp/cr_scfp_file.log');
    and which was conditioned on the the button P2_RUN_SHELL.
    It works like a charm.
    Note: since you can run your own scripts using this method, you can encapsulate a series of commands in a UNIX shell script and invoke that script from Apex. This allows you to be able to test or run you commands from the command line as well as Apex and makes it easier to develop/debug/enhance the scripts in the future.
    Ackness

  • Adobe Configurator - how to invoke action or script from html widget?

    How to invoke action or script from html wiget in Adobe Configurator?
    Please help! I tried to make it about 5 hours!
    I need something like that:
    I click link or image
    ...and it runs action.
    Thanks!

    If you click on the question mark ( as shown below) on the right of Configurator  2 window
    the user guide installed on your computer within Configurator 2  will open
    Anyway once you have your action or script button  in your panel you must select it and configure it in the  inspector palette

  • How to open a page from a Form and pass parameters to the form on that page

    I found a similar example on this forum, but it did not work for me:
    declare
    l_names owa.vc_arr;
    l_values owa.vc_arr;
    i number;
    begin
    PORTAL.wwpro_api_parameters.retrieve(l_names, l_values);
    FOR i in 1..l_names.count
    LOOP
    htp.p(l_names(i) || ' ' || l_values(i));
    END LOOP;
    end;
    By using this method i get the parameters for the Form, like the session ID, but not the parameters for the Page that the form is displayed in.
    Another method I tried:
    To open a Form from a Form and pass parameters works fine like this:
    --In the After processing page PL/SQL event.
    declare
    v_id number;
    blk varchar2(10):='DEFAULT';
    Begin
    v_id:=p_session.get_value_as_number (p_block_name=&gt;blk,p_attribute_name=&gt;'A_ID');
    if v_id &gt; 0 then
    htp.formOpen('PORTAL.wwa_app_module.link?p_arg_names=_moduleid&p_arg_values=2649500412&p_arg_names=_show_header&p_arg_values=YES&p_arg_names=ID&p_arg_values='||to_char(v_id),'post');
    htp.formSubmit(NULL,'Upload Files');
    htp.formClose;
    end if;
    End;
    But I want to open a Page containing the Form instead of just opening the Form. Is this possible to open a Page and pass paramters to the page, and then let the form inside the Page access the passed paramters. The reason for this is that a Form cannot be based on a page template, or can it? When opening the form i want to keep the left menu, which I can if it is a page based on my template with the left menu.
    Best regards
    Halvor

    Hi,
    You can do this by calling the url of the page with the form. You can then use p_arg_names and p_arg_values to pass parameters. In the called form you can get the value from p_arg_names and p_arg_values and assign it to the form field.
    You can call this code in the success procedure of the calling form.
    declare
    v_id number;
    blk varchar2(10):='DEFAULT';
    v_url varchar2(2000);
    Begin
    v_id:=p_session.get_value_as_number (p_block_name=>blk,p_attribute_name=>'A_ID');
    v_url := <page_url>;
    if v_id > 0 then
    call(v_url||'&p_arg_names=id&p_arg_values='||v_id);
    end if;
    End;
    In the called form in "Before displaying form" plsql section write this code.
    for i in 1..p_arg_names.count loop
    if p_arg_names(i) = 'id' then
    p_session.set_value(
    p_block_name => blk,
    p_attribute_name => 'A_ID',
    p_value => p_arg_values(i)
    end if;
    end loop;
    This code picks up the value from p_arg_values and assigns it to the form field.
    Hope that helps.
    Thanks,
    Sharmila

  • Unix Script and Jar files

    I am in the process of designing a new system and wonder if the following is possible.
    I want a UNIX script to execute a Jar file with a status of 1 or 0 (based of success/failure) being passed back from the Jar to the UNIX script.
    I know a Jar file can be executed from a UNIX script but not sure about the passing of a message.
    Would public static void main(String[] args) make it impossible to pass a message or is there some way around this ?
    If a message can be passed back to the Script how would it pick it up ? - `echo $?` ?
    Message was edited by:
    palmeal

    Right, in the shell script you have in $? the return
    code of the last command.
    java ...
    if test $? -eq 0
    then
    echo java was ok
    e
    echo java oops
    If a message can be passed back to the Script howwo
    However the return code is no message.I really don't understand! Are you saying you just want to read something in the shell script that is generated by the Java program but the Java program must keep running and not terminate? If so then use stdout or stderr (as BIJ001 says).

  • Triggering background job event from Unix script

    Hi all,
      I am having one question regarding triggering of background job in SAP using Events from Unix script. Is this possible? If so, can anyboy provide some sample code related to Unix script and how do we communicate to SAP from Unix system. Actually, here the backend of R/3 system is MSSQL. I am having a program in R/3 system which is scheduled as a background job based upon event trigger. I want to trigger that even from the unix script.
      Appreciate for your help in advance.
    Thanks,
    Adithya K

    Hi,
    Check if this can help you
    http://help.sap.com/saphelp_sm32/helpdata/en/fa/096e6b543b11d1898e0000e8322d00/content.htm
    Regards,
    Atish

  • Need help!: How to covert Excel into BLOB and pass into procedure?

    Hi,
    I am writing a program in which I am uploading file from front-end and passing that file into Oracle procedure in BLOB format.
    Can someone help me ,that **how to convert Excel sheet into BLOB and then how we can pass that BLOB object to procedure in oracle*.
    Any help will greatly appreciated.
    Thanks

    Guys,
    I am able to convert FormFile into byutes using getFileData();
    But when I am tryint oconvert into BLOB,it is dhoowing me the error.
    Please find the complete details below.
    I am trying to Upload one file using FormFile of Struts and I need to pass that Form File into one procedure having BLOB as aIn parameter. SO I need to convert that file into BLOB object
    The code that I am trying is :
    try{
    BLOB blob= BLOB.getEmptyBLOB();
    System.out.println("before");
    blob.setBytes(theFile.getFileData());
    System.out.println("after");
    cs.setBlob(3, blob);
    }catch(Exception e){System.out.println("in the BLOB "+e);}
    After running the code,I am getting the following error
    java.lang.ArrayIndexOutOfBoundsException
    at java.lang.System.arraycopy(Native Method)
    at oracle.jdbc.driver.DatumBinder.bind(OraclePreparedStatement.java:15839)
    at oracle.jdbc.driver.OraclePreparedStatement.setupBindBuffers(OraclePreparedStatement.java:2865)
    at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:2150)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3279)
    at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3389)
    at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4222)
    at dms.bo.impl.LoadManagement.UploadMetadataDAOImpl$1.doInCallableStatement(UploadMetadataDAOImpl.java:38)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:953)
    at dms.bo.impl.LoadManagement.UploadMetadataDAOImpl.getBlobString(UploadMetadataDAOImpl.java:28)
    at dms.web.action.LoadManagement.UploadMetadataAction.perform(UploadMetadataAction.java:33)
    at dms.web.action.common.BaseAction.execute(BaseAction.java:17)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Thread.java:619
    So with

  • Call tcode from alv report and passing  group of values

    hi all .
    i want to call tcode from alv report and passing an internal table or group of values to a selection option of that t code ? how
    ex. passing group of GL to fbl3n and display the detials of all .
    thank you

    Dear,
    You have done a small mistake
    --> rspar_line-option = 'EQ'.
         rspar_line-HIGH = PDATE-HIGH.
    u r passing "high" value and in "option u r passing "EQ" so how it will work!!!
    So if u r passing only 1 date or more dates like 01.01.2010 , 15.02.2010 , 10.03.2010 then pass
    rspar_line-selname = 'SO_BUDAT'.
    rspar_line-kind = 'S'.
    rspar_line-sign = 'I'.
    rspar_line-option = 'EQ'.
    rspar_line-LOW = PDATE-HIGH.
    APPEND rspar_line TO rspar_tab.
    or if u r passing low & high date means in range like 01.01.2010 to 30.01.2010, then pass
    rspar_line-selname = 'SO_BUDAT'.
    rspar_line-kind = 'S'.
    rspar_line-sign = 'I'.
    rspar_line-option = 'BT''.
    rspar_line-LOW = PDATE-LOW.
    rspar_line-HIGH = PDATE-HIGH.
    APPEND rspar_line TO rspar_tab.
    try above code , hope it helps...
    i think u cannot use "call transaction using bdcdata" in ur case bcoz as u said in ur 1st post u want to display the details of all but still if u want to use then u should pass all parameters in  loop.
    PROGRAM
    DYNPRO
    DYNBEGIN
    FNAM
    FVAL
    ex:-
    LOOP AT GT_TEMP INTO GS_TEMP.
    CLEAR bdcdata_wa.
    bdcdata_PROGRAM = 'SAPXXXX'.
    bdcdata_DYNPRO = '1000'.
    bdcdata_DYNBEGIN = 'X'.
    bdcdata_wa-fnam = '''.
    bdcdata_wa-fval = ''.
    APPEND bdcdata_wa TO bdcdata_tab.
    CLEAR bdcdata_wa.
    bdcdata_PROGRAM = ''.
    bdcdata_DYNPRO = ''.
    bdcdata_DYNBEGIN = ''.
    bdcdata_wa-fnam = 'SD_SAKNR'.
    bdcdata_wa-fval = GS_TEMP-GLACCOUNT.
    APPEND bdcdata_wa TO bdcdata_tab.
    CLEAR bdcdata_wa.
    bdcdata_PROGRAM = ''.
    bdcdata_DYNPRO = ''.
    bdcdata_DYNBEGIN = ''.
    bdcdata_wa-fnam = 'BDC_OKCODE'.
    bdcdata_wa-fval = 'XXX'.
    APPEND bdcdata_wa TO bdcdata_tab.
    ENDLOOP.
    try above code if u r using call transaction...
    Edited by: mihir6666 on Jul 9, 2011 3:10 PM
    Edited by: mihir6666 on Jul 9, 2011 3:11 PM
    Edited by: mihir6666 on Jul 9, 2011 3:13 PM

  • Through a java prog how to execute a unix script ?

    Hi !! I am a Java Developer . I have to work in Unix and Java in combination. Can you plz suggest me a solution for the below queries --
    1. Through a java prog how to execute a unix script.
    2. How to send the o/p of the script to a java prog so that it can be used in the java program to the prupose of display etc..

    Try this
    Process process = Runtime.getRuntime().exec("ps -ef");//write Your command here
                   InputStream in = process.getInputStream();
                   BufferedReader bufReader = new BufferedReader(new InputStreamReader(in));
                   String data=null;
                   while((data = bufReader.readLine())!=null)
                        System.out.println(data);   //do whatever you want to do with the output

  • Reading Data from Unix file and write into an Internal table

    Dear all,
                     I am having an requirement of reading data from unix file and write the same into an internal table..how to do that ...experts please help me in this regard.

    Hi,
    do like this
    PARAMETERS: p_unix LIKE rlgrap-filename OBLIGATORY.
    DATA: v_buffer(2047) TYPE c.
    DATA: BEGIN OF i_buffer OCCURS 0,
            line(2047) TYPE c,
    END OF i_buffer.
    * Open the unix file..
    OPEN DATASET p_unix FOR INPUT IN TEXT MODE.
    <b>IF sy-subrc NE 0.
    *** Error Message "Unable to open file.
    ELSE.</b>
       DO.
         CLEAR: v_buffer.
         READ DATASET p_unix INTO v_buffer.
         IF sy-subrc NE 0.
            EXIT.
         ENDIF.
         MOVE v_buffer TO i_buffer.
         APPEND i_buffer.
      ENDDO.
    ENDIF.
    CLOSE DATASET p_unix.
    <b>Reward points if it helps,</b>
    Satish

  • How do I get my photos and music back into new version iTunes from my iPad?

    I have the new version of iTunes (11 0 2 26) for Windows which installed over my old copy. I see none of my music etc even after it claims to have synced and backed up. How do I get my photos and music back into iTunes from my iPad? It syncs OK with calendar and contacts from Outlook and I can force copying of apps and books but why does it not show music and photos in the iTunes library? help please.
    David

    Empty/corrupt library after upgrade/crash
    Hopefully it's not been too long since you last upgraded iTunes, in fact if you get an empty/incomplete library immediately after upgrading then with the following steps you shouldn't lose a thing or need to do any further housekeeping.  Note that in iTunes 11 an "empty" library may show your past purchases with links to stream or download them.
    In the Previous iTunes Libraries folder should be a number of dated iTunes Library files. Take the most recent of these and copy it into the iTunes folder. Rename iTunes Library.itl as iTunes Library (Corrupt).itl and then rename the restored file as iTunes Library.itl. Start iTunes. Should all be good, bar any recent additions to or deletions from your library.
    Alternatively, depending on exactly when and why the library went missing, there may be a more recent .tmp file in the main iTunes folder that can be renamed as iTunes Library.itl to restore the library to a recent state.
    See iTunes Folder Watch for a tool to catch up with any changes since the backup file was created.
    When you get it all working make a backup!
    Should you be in the unfortunate position where you are no longer able to access your original library, or a backup of it, then see Recover your iTunes library from your iPod or iOS device.
    tt2

  • HT4972 how do i move my apps and music back to my iphone from the itunes library

    how do i move my apps and music back to my iphone from ituneslibrary

    See Here  >  Syncing with iTunes
    From Here  >  http://www.apple.com/support/iphone/syncing/
    More Info Here  >  iPhone User Guide

  • How to retrieve the procedure value and pass the value to a form field

    How to retrieve the procedure value and pass the value to a form field?

    Set property for the field and the value is the actual procedure/function.
    Cheers

Maybe you are looking for

  • How to hide not all but a specific database on a SQL Server 2008 R2 instance?

    Hello everyone,       I need help from all the SQL Server database security experts out there. Any solution/help or work-around will be really appreciated. Here is the scenario; our client is using our application which is a windows forms application

  • Dead Links on web page

    Please use this forum to provide feedback about OTN content/services. All other posts will be DELETED. The following links are not operational as of today. I tried each of them several times. Please advise as I have a customer who needs to access the

  • Large iTunesU Integration - Got any advice?

    Greetings. My name is George Bray from the Australian National Uni in Canberra. I've been anointed the person to integrate our existing lecture recording systems and authentication with iTunesU. (Lucky me!) We have 3500 courses and each one has poten

  • 802.1x Query

    Hi, I am implementing 802.1x in my network where I have some avaya switches & some cisco switches. My First question is that how can I implement it on avaya switches.Second how can I configure a cisco switch port on which another cisco switch is conn

  • Data Load Error in Rate Application

    Hello, We are trying to load data to RATE application from a BW infoprovider via data manager.  We are encountering the below error Cannot access the member (ACTUAL) of dimension (CATEGORY) Line 0 :ACTUAL,BRL,AVG,GLOBAL,2009.APR,0.0000000 All dimensi