Networker

[Networker] Still can't do this in Perl

2004-11-22 10:55:48
Subject: [Networker] Still can't do this in Perl
From: George Sinclair <George.Sinclair AT NOAA DOT GOV>
To: NETWORKER AT LISTMAIL.TEMPLE DOT EDU
Date: Mon, 22 Nov 2004 10:58:16 -0500
I am still unable to perform the equivalent of the following simple
Bourne shell script in Perl:

#!/bin/sh
/usr/sbin/nsradmin -s orion -i -<<EOF
print type: NSR $1; name: $2
EOF

I invoke this as: ./nsradmin.sh client client_name

This is just an example. My objective is to be able to run the nsradmin
utility from within a Perl script and pass it the desired information
via the Perl script and NOT a temporary file. I want to be able to pass
in the information that nsradmin will use, BUT I don't want to have to
first create a "real" file to hold it or have the script create the
file. I want to bypass the need to have to do that all together. I then
need to be able to capture the output from the nsradmin program.

I submitted this question prior and received some nice suggestions but
none of these worked. Here are the things I've tried that do not work:

Option 1:
#!/usr/bin/perl
system ("/usr/sbin/nsradmin -s server -i " . <<EOF);
print type: NSR $ARGV[0]; name: $ARGV[1]
EOF

Invoked as: ./nsradmin.pl client client_name

Produces following output:
nsradmin: print: No such file or directory
sh: name:: command not found

Option 2: same as 1 but tried "-i . -<<EOF);"

nsradmin: -print: No such file or directory
sh: name:: command not found

Option 3:
#!/usr/bin/perl
open (ADM, "|/usr/sbin/nsradmin -s server -i") or
   die "Couldn't open pipe to nsradmin.\n";
print ADM "type: NSR $ARGV[0]; name: $ARGV[1]\n";

Invoked as: same as option 1

Produces following output:
usage: nsradmin [-c] [-i file] [-s server] [-p prognum] [-v version]
[query]...
usage: nsradmin [-c] [-i file] [-f resfile] [-t typefile] ... [query]...
Broken pipe

Option 4:
!/usr/bin/perl
@reply = `/usr/sbin/nsradmin -s orion -i <<EOF`;
print type: NSR $ARGV[0]; name: $ARGV[1]
EOF

Invoked as: same as option 1

Produces following output:
syntax error at ./c.pl line 3, near "type:"
syntax error at ./c.pl line 4, next token ???
Execution of ./c.pl aborted due to compilation errors.

I've tried all kinds of options involving '.', '-' characters. How can I
do this? Seems so easy and yet so frustrating.

Thanks.

George

--
Note: To sign off this list, send a "signoff networker" command via email
to listserv AT listmail.temple DOT edu or visit the list's Web site at
http://listmail.temple.edu/archives/networker.html where you can
also view and post messages to the list. Questions regarding this list
should be sent to stan AT temple DOT edu
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=