Call Unix Script from PeopleCode

Your rating: None

A function to call UNIX and/or shell script from PeopleCode.

/*call unix script from PeopleCode*/
Function CallScript;

   /*According to PeopleBooks, PS_HOME is always prefixed to the file location*/
   &exitCode = Exec("/path/to/script/scriptname ", True);

End-Function;

The Exec command has changed in PT8.4x so the above function will be:

Function CallScript;
 
   /*Use %Exec_Asynchronous if it is not important to wait for a response from the called script*/
   &exitCode = Exec(&PS_HOME | "path/to/script/scriptname", %Exec_Synchronous + %FilePath_Absolute);
   
   If &exitCode <> 0 Then
      MessageBox(0, "", 0, 0, ("Script was not Successful!  Exit code returned by script was " | &exitCode));
   End-If;
   
End-Function;

If you are using the Exec call inside of an Application Engine and you are calling it in a Synchronous mode, make sure you commit your work before you call it, otherwise, you will get a run time error.

CommitWork();
CallScript();

Please try to help out with unanswered topics on the forum. Chances are you have had the same issue/question some time in your IT career!

Comments

Have a question? Please ask it on the forum instead.

Component properties stored in which metadata table

Guest's picture

Through application designer when I open existing Component and right click on the component name I see Component properties.
Further On selecting internet tab,Toolbar details. Which tables keeps information about the toolbar actions Like Save , Cancel, Return to list etc for a component.

Re: Component properties stored in which metadata table

Posts: 302
Join date: 06/23/08
Lepa's picture

Your question is unrelated to this post. I will still give you a hit but please post questions related to the topic you're commenting on.

Have you looked at this post? You need to look at table PSPNLGRPDEFN, the values are stored as a number under column TBARBTN (I think). To test this, query a component, right down the number, change the properties save and then query it again. Compare the two results and you'll see which field has changed.

Give back to the community and help it grow!
* Help with unanswered forum questions and issues
* Register or login to share your knowledge at your own blog

Re: Call Unix Script from PeopleCode

Jonathan's picture

Great code, this works perfect for me in DEV.

The UNIX script I wrote is getting a file from an external web site, and putting it on the Unix Box, so my A/E can open it and process the data. However, the script I wrote is currently hard coded with the /psoft/csdev/custom/ directory. Is there a way to pass a PS_HOME directory to the Unix script? Ideally, I'd like "&ps_home/custom" so I wouldn't have to recode this script when it goes from dev to test to qa to production.

Thanks!

Re: Call Unix Script from PeopleCode

Posts: 302
Join date: 06/23/08
Lepa's picture

Hey Jonathan,

your PS_HOME might be something like this:
PS_HOME=/psoft/$ORACLE_SID where $ORACLE_SID is csdev in dev and will change according to your environment. If $ORACLE_SID is not set up on the server side then get it from your PeopleCode. It should be the last part of your ps_home (you need to do the substring) and then pass it to the script.

&PS_HOME = LTrim(RTrim(GetEnv("PS_HOME"), "/"), "/");

 &exitCode = Exec(&PS_HOME | "path/to/script/scriptname " | &oracle_sid, %Exec_Synchronous + %FilePath_Absolute);

In your script, receive the value as such:
OracleSID=$3
if [ "$ORACLE_SID" = "" ]
then
  ORACLE_SID=$3
fi

Please use the forum if you want to discuss this more :)

Give back to the community and help it grow!
* Help with unanswered forum questions and issues
* Register or login to share your knowledge at your own blog

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <div> <pre> <br> <code> <a> <em> <blockquote> <strong> <ul> <ol> <li> <dl> <dt> <b> <p> <h1> <h2> <u> <img>
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>.

More information about formatting options

CAPTCHA
The question below is to prevent automated spam submissions.
2 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.