"

T

Tony

Hi,
Whenever I run the system command in perl and try to make sure it runs
sucessfully otherwise do something else, even for the most basic
system commands, I get "Inappropriate ioctl for device"

For example, the code:

$testdate = system("date") or die "can't run /usr/bin/date: $!";
print "$testdate";

returns:

Mon Sep 13 17:01:38 UTC 2004
can't run /usr/bin/date: Inappropriate ioctl for device at test.pl
line 7, <STDIN> line 4.

So it runs the command successfully, but dies anyway. Yes I know
there's another way to do date, this is just an example of the problem
I have. I need to use the system() command for other things, but no
matter what command I do I get the above. I have tried
$varname=system(command) and then testing $varname, but that doesn't
return anything.

Can anyone help? I don't want to use another module, I'm sure I must
be missing something here. Thanks in advance!

operating system is fedora linux, perl version is v5.8.3.

Tony
 
Z

Zebee Johnstone

In comp.lang.perl.misc on 13 Sep 2004 00:20:34 -0700
Tony said:
Hi,
$testdate = system("date") or die "can't run /usr/bin/date: $!";
print "$testdate";

from perldoc -f system
(you knew someone was going to mention that, didn't you....)

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

You can check all the failure possibilities by
inspecting `$?' like this:

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


Read the whole thing, you will likely be enlightened.

Zebee
 
M

Mark Clements

Tony said:
Hi,
Whenever I run the system command in perl and try to make sure it runs
sucessfully otherwise do something else, even for the most basic
system commands, I get "Inappropriate ioctl for device"

For example, the code:

$testdate = system("date") or die "can't run /usr/bin/date: $!";
print "$testdate";
are you sure it is running /usr/bin/date? Your error message is making
an assumption about the path of date that may not be correct.

returns:

Mon Sep 13 17:01:38 UTC 2004
can't run /usr/bin/date: Inappropriate ioctl for device at test.pl
line 7, <STDIN> line 4.
system returns the exit status of the invoked program and not its output.

perldoc -f system
perldoc -f perlop (you need to look at `` (backticks) or qx{}

So it runs the command successfully, but dies anyway. Yes I know
there's another way to do date, this is just an example of the problem
System is returning 0 signifying a successful command invocation. You
need to invert the sense of your test for success if you are going to
use system.

ie

die "$!" if system("date");

but since you want to capture the output you need to use backticks or qx

eg
my $output = qx(date);


By the way, you need to put a little more thought into your subject lines.

Mark
 
T

Tintin

[did your finger slip when writing the subject line?]

Whenever I run the system command in perl and try to make sure it runs
sucessfully otherwise do something else, even for the most basic
system commands, I get "Inappropriate ioctl for device"

For example, the code:

$testdate = system("date") or die "can't run /usr/bin/date: $!";
print "$testdate";

returns:

Mon Sep 13 17:01:38 UTC 2004
can't run /usr/bin/date: Inappropriate ioctl for device at test.pl
line 7, <STDIN> line 4.

So it runs the command successfully, but dies anyway. Yes I know
there's another way to do date, this is just an example of the problem
I have. I need to use the system() command for other things, but no
matter what command I do I get the above. I have tried
$varname=system(command) and then testing $varname, but that doesn't
return anything.

Can anyone help? I don't want to use another module, I'm sure I must
be missing something here. Thanks in advance!

Seriously, where did you learn to use system? Did you read the
documentation for it, or did you see an example somewhere. If you saw an
example, it was obviously a bad example.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top