Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning value from Connect Direct from within Perl

Status
Not open for further replies.

s2budd

Technical User
May 15, 2001
30
GB
Hiya

I don't know Perl and I've got a bit of a problem.

I am calling Connect Direct from Perl to transfer a file from one machine to another.

I'm using:
(the stuff in "'s works OK) - but I'm trying to get a valid
return code)
The process below fails - but still returns "0". It should be returning "8".

$return_value = system(&quot;d:/Progra~1/CDNT/Direct -u cdgw3usr -p condir -x > $condir_out < $temp_file&quot;);
die &quot;problem: $?&quot; unless $return_value == 0;

I've also tryed:
$return_value = `d:/Progra~1/CDNT/Direct -u cdgw3usr -p condir -x > $condir_out < $temp_file`);
and
$return_value = `command -c d:/Progra~1/CDNT/Direct -u cdgw3usr -p condir -x > $condir_out < $temp_file`;


all above examples return &quot;0&quot; for both

$return_value
$?


Does anybody have any ideas.
Many thanks

Stuart Budd
Zurich Bank



 
Strange.....

Does the process return the correct value from the command line and inside a DOS batchfile?

You backticks examples should look more like this by the way:

$output = `your_command and parameters`;
$return_val = $?;

The use of backticks means that any printed output from the command will end up in the variable on the left hand side of the '=' sign. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
From &quot;perldoc -f system&quot;:

Does exactly the same thing as &quot;C<exec LIST>&quot;, except that a fork is done
first, and the parent process waits for the child process to complete.
Note that argument processing varies depending on the number of
arguments. If there is more than one argument in LIST, or if LIST is
an array with more than one value, starts the program given by the
first element of the list with arguments given by the rest of the list.
If there is only one scalar argument, the argument is
checked for shell metacharacters, and if there are any, the entire
argument is passed to the system's command shell for parsing (this is
C</bin/sh -c> on Unix platforms, but varies on other platforms). If
there are no shell metacharacters in the argument, it is split into
words and passed directly to C<execvp()>, which is more efficient.

The return value is the exit status of the program as
returned by the C<wait()> call. To get the actual exit value divide by
256. See also L</exec>. This is I<NOT> what you want to use to capture
the output from a command, for that you should use merely backticks or
C<qx//>, as described in L<perlop/&quot;`STRING`&quot;>.

Like C<exec()>, C<system()> allows you to lie to a program about its name if
you use the &quot;C<system PROGRAM LIST>&quot; syntax. Again, see L</exec>.

Because C<system()> and backticks block C<SIGINT> and C<SIGQUIT>, killing the
program they're running doesn't actually interrupt your program.

@args = (&quot;command&quot;, &quot;arg1&quot;, &quot;arg2&quot;);
system(@args) == 0
or die &quot;system @args failed: $?&quot;

You can check all the failure possibilities by inspecting
C<$?> like this:

$exit_value = $? >> 8;
$signal_num = $? & 127;
$dumped_core = $? & 128;

When the arguments get executed via the system shell, results
and return codes will be subject to its quirks and capabilities.
See L<perlop/&quot;`STRING`&quot;> and L</exec> for details.
---------------------------------------

Note from this that a better way to invoke system is using:

@args = (&quot;command&quot;, &quot;arg1&quot;, &quot;arg2&quot;);
system(@args) == 0
or die &quot;system @args failed: $?&quot;

and you should get the commands true return code back like this:

$exit_value = $? >> 8;
$signal_num = $? & 127;
$dumped_core = $? & 128;

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
Hardy -- as the OP said, in this case the system() function does not seem to be returning a return value at all. I suspect that this is because the command being called is not behaving correctly, rather than a problem with the system() function. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Many thanks for your help.

After lots of investigation I found out from Sterling Commerce that Connect Direct does not produce a return value on NT.

This would be the reason why the return value that I was getting was always 0.

Many thanks

Stuart Budd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top