<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Capture Return value of Script in CL Program</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/capture-return-value-of-script-in-cl-program/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/capture-return-value-of-script-in-cl-program/</link>
	<description></description>
	<lastBuildDate>Thu, 20 Jun 2013 03:04:31 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: wilsonalano</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/capture-return-value-of-script-in-cl-program/#comment-89179</link>
		<dc:creator>wilsonalano</dc:creator>
		<pubDate>Wed, 09 Mar 2011 21:52:49 +0000</pubDate>
		<guid isPermaLink="false">#comment-89179</guid>
		<description><![CDATA[Try this

#!/bin/bash
# This is a SFTP script
sftp -oPort=6222 -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no User@TargetSys
cd folder1
put fileName
#End of script
exit $?

Regards,
Wilson]]></description>
		<content:encoded><![CDATA[<p>Try this</p>
<p>#!/bin/bash<br />
# This is a SFTP script<br />
sftp -oPort=6222 -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no User@TargetSys<br />
cd folder1<br />
put fileName<br />
#End of script<br />
exit $?</p>
<p>Regards,<br />
Wilson</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tomliotta</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/capture-return-value-of-script-in-cl-program/#comment-89131</link>
		<dc:creator>tomliotta</dc:creator>
		<pubDate>Wed, 09 Mar 2011 00:24:01 +0000</pubDate>
		<guid isPermaLink="false">#comment-89131</guid>
		<description><![CDATA[Here&#039;s a very basic example of the general technique:&lt;pre&gt;
pgm

   dcl   &amp;MsgId       *char    7
   dcl   &amp;MsgDta      *char  128
   dcl   &amp;ExitSts     *int           value( 0 )

   qsh cmd(&#039;exit 79&#039;)
   rcvmsg      msgtype( *LAST ) rmv( *NO ) msgdta( &amp;MsgDta ) +
                 msgid( &amp;MsgId )
   if ( &amp;MsgId *eq &#039;QSH0005&#039; )  do
      chgvar   &amp;ExitSts     %bin( &amp;MsgDta 1 4 )
   enddo

   dmpclpgm

   return

endpgm&lt;/pre&gt;
You should be able to paste that into a CL source member, compile it and run it. It runs the most basic QShell command to set an EXIT status of &quot;79&quot;. After the QSH command returns, the CL receives the last message on the program&#039;s message queue to see if it&#039;s QSH0005. If it is, it pulls the 4-byte binary value from the received message data.

The DMPCLPGM command then dumps the program variables to show that the first four bytes of &amp;MsgDta contain the hex value of the EXIT status and that the &amp;ExitSts variable contains the integer representation of those four bytes. The EXIT command that is run by QSH should have the same value.

You could use RCVMSG after your MONMSG-ENDDO. The MONMSG DO-group would catch exceptions from your STRQSH command, and RCVMSG would receive whatever the last message was.

You should probably also put a RETURN statement inside of your MONMSG DO-group so that statemants after the ENDDO aren&#039;t executed. There are lots of other ways to take care of that, but a RETURN is straightforward and clear to anyone.]]></description>
		<content:encoded><![CDATA[<p>Here&#8217;s a very basic example of the general technique:
<pre>
pgm

   dcl   &amp;MsgId       *char    7
   dcl   &amp;MsgDta      *char  128
   dcl   &amp;ExitSts     *int           value( 0 )

   qsh cmd('exit 79')
   rcvmsg      msgtype( *LAST ) rmv( *NO ) msgdta( &amp;MsgDta ) +
                 msgid( &amp;MsgId )
   if ( &amp;MsgId *eq 'QSH0005' )  do
      chgvar   &amp;ExitSts     %bin( &amp;MsgDta 1 4 )
   enddo

   dmpclpgm

   return

endpgm</pre>
<p>You should be able to paste that into a CL source member, compile it and run it. It runs the most basic QShell command to set an EXIT status of &#8220;79&#8243;. After the QSH command returns, the CL receives the last message on the program&#8217;s message queue to see if it&#8217;s QSH0005. If it is, it pulls the 4-byte binary value from the received message data.</p>
<p>The DMPCLPGM command then dumps the program variables to show that the first four bytes of &amp;MsgDta contain the hex value of the EXIT status and that the &amp;ExitSts variable contains the integer representation of those four bytes. The EXIT command that is run by QSH should have the same value.</p>
<p>You could use RCVMSG after your MONMSG-ENDDO. The MONMSG DO-group would catch exceptions from your STRQSH command, and RCVMSG would receive whatever the last message was.</p>
<p>You should probably also put a RETURN statement inside of your MONMSG DO-group so that statemants after the ENDDO aren&#8217;t executed. There are lots of other ways to take care of that, but a RETURN is straightforward and clear to anyone.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: viveksharma</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/capture-return-value-of-script-in-cl-program/#comment-89088</link>
		<dc:creator>viveksharma</dc:creator>
		<pubDate>Tue, 08 Mar 2011 07:12:58 +0000</pubDate>
		<guid isPermaLink="false">#comment-89088</guid>
		<description><![CDATA[The script that I have created is as below:

#!/bin/bash                                                                                                   
# This is a SFTP script                                                                                       
success=0                                                                                                     
sftp -oPort=6222 -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no User@TargetSys &#124;&#124; success=$?&lt;&lt;EOF
cd folder1
put fileName
EOF                                                                                                           
#End of script                                                                                                
exit $success          

I am trying to capture the value error if any in success field.

How ever I am facing the issue that the script runs only the first line i.e. &quot;sftp -b ..........&quot; command and gives the value to the success field.
The rest of the commands are not executed.

The next issue that I am facing is how to capture this return value in my cl program.

At present my CL code is:

PGM                                                                
                                                                   
 /* IF VARIABLES WERE SET PREVIOUSLY, REMOVE THEM SO THAT OUR +    
    ADDENVVAR COMMANDS WORK.                                  */   
                                                                   
            DCL        VAR(&amp;QSCOMD) TYPE(*CHAR) LEN(200) +         
                         VALUE(*BLANKS)                            
            CHGVAR     VAR(&amp;QSCOMD) VALUE(&#039;ksh -x sftpscript.sh&#039;)  
                                                                   
 /* SET THE COMMAND OUTPUT TO NONE, AND TELL QSH TO ISSUE +        
    ESCAPE MESSAGES FOR ERRORS.                               */   
                                                                   
            ADDENVVAR  ENVVAR(QIBM_QSH_CMD_OUTPUT) VALUE(NONE) +   
                         LEVEL(*JOB) REPLACE(*YES)                 
            ADDENVVAR  ENVVAR(QIBM_QSH_CMD_ESCAPE_MSG) VALUE(Y) +  
                         LEVEL(*JOB) REPLACE(*YES)                 
 /* EXECUTE OUR QSHELL COMMAND */                                  
                                                                   
       STRQSH CMD(&amp;QSCOMD)                                         
       MONMSG MSGID(QSH0000)                         EXEC(DO)                     
                   SNDPGMMSG  MSGID(CPF9897) MSGF(QCPFMSG) MSGDTA(&#039;QShell +       
                                command failed!&#039;)                                 
              ENDDO                                                               
       ENDPGM]]></description>
		<content:encoded><![CDATA[<p>The script that I have created is as below:</p>
<p>#!/bin/bash<br />
# This is a SFTP script<br />
success=0<br />
sftp -oPort=6222 -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no User@TargetSys || success=$?&lt;&lt;EOF<br />
cd folder1<br />
put fileName<br />
EOF<br />
#End of script<br />
exit $success          </p>
<p>I am trying to capture the value error if any in success field.</p>
<p>How ever I am facing the issue that the script runs only the first line i.e. &#8220;sftp -b &#8230;&#8230;&#8230;.&#8221; command and gives the value to the success field.<br />
The rest of the commands are not executed.</p>
<p>The next issue that I am facing is how to capture this return value in my cl program.</p>
<p>At present my CL code is:</p>
<p>PGM                                                                </p>
<p> /* IF VARIABLES WERE SET PREVIOUSLY, REMOVE THEM SO THAT OUR +<br />
    ADDENVVAR COMMANDS WORK.                                  */   </p>
<p>            DCL        VAR(&amp;QSCOMD) TYPE(*CHAR) LEN(200) +<br />
                         VALUE(*BLANKS)<br />
            CHGVAR     VAR(&amp;QSCOMD) VALUE(&#8216;ksh -x sftpscript.sh&#8217;)  </p>
<p> /* SET THE COMMAND OUTPUT TO NONE, AND TELL QSH TO ISSUE +<br />
    ESCAPE MESSAGES FOR ERRORS.                               */   </p>
<p>            ADDENVVAR  ENVVAR(QIBM_QSH_CMD_OUTPUT) VALUE(NONE) +<br />
                         LEVEL(*JOB) REPLACE(*YES)<br />
            ADDENVVAR  ENVVAR(QIBM_QSH_CMD_ESCAPE_MSG) VALUE(Y) +<br />
                         LEVEL(*JOB) REPLACE(*YES)<br />
 /* EXECUTE OUR QSHELL COMMAND */                                  </p>
<p>       STRQSH CMD(&amp;QSCOMD)<br />
       MONMSG MSGID(QSH0000)                         EXEC(DO)<br />
                   SNDPGMMSG  MSGID(CPF9897) MSGF(QCPFMSG) MSGDTA(&#8216;QShell +<br />
                                command failed!&#8217;)<br />
              ENDDO<br />
       ENDPGM</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tomliotta</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/capture-return-value-of-script-in-cl-program/#comment-89065</link>
		<dc:creator>tomliotta</dc:creator>
		<pubDate>Tue, 08 Mar 2011 02:14:21 +0000</pubDate>
		<guid isPermaLink="false">#comment-89065</guid>
		<description><![CDATA[It&#039;s not clear what you might see without knowing a little more about your CL and the STRQSH command as well as the script. However, there&#039;s a good chance the message ID QSH0005 will be returned to your CL program as a *COMP message. The message description is in message file QZSHMSGF in library QSHELL.

You should be able to receive that message and access the exit status in the message data. It&#039;s returned as a 4-byte binary field.

Tom]]></description>
		<content:encoded><![CDATA[<p>It&#8217;s not clear what you might see without knowing a little more about your CL and the STRQSH command as well as the script. However, there&#8217;s a good chance the message ID QSH0005 will be returned to your CL program as a *COMP message. The message description is in message file QZSHMSGF in library QSHELL.</p>
<p>You should be able to receive that message and access the exit status in the message data. It&#8217;s returned as a 4-byte binary field.</p>
<p>Tom</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: danthedane</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/capture-return-value-of-script-in-cl-program/#comment-89040</link>
		<dc:creator>danthedane</dc:creator>
		<pubDate>Mon, 07 Mar 2011 15:13:32 +0000</pubDate>
		<guid isPermaLink="false">#comment-89040</guid>
		<description><![CDATA[Pls be more specific.  Is your script started from a CL-pgm ?  Pls provide relevant extract from your code.

DanF]]></description>
		<content:encoded><![CDATA[<p>Pls be more specific.  Is your script started from a CL-pgm ?  Pls provide relevant extract from your code.</p>
<p>DanF</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 3/8 queries in 0.024 seconds using memcached
Object Caching 325/326 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-06-20 03:46:11 -->