"

Discussion in 'Perl Misc' started by Tony, Sep 13, 2004.

  1. Tony

    Tony Guest

    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
    Tony, Sep 13, 2004
    #1
    1. Advertising

  2. In comp.lang.perl.misc on 13 Sep 2004 00:20:34 -0700
    Tony <> wrote:
    > 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
    Zebee Johnstone, Sep 13, 2004
    #2
    1. Advertising

  3. Tony wrote:
    > 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
    Mark Clements, Sep 13, 2004
    #3
  4. Tony

    Tintin Guest

    "Tony" <> wrote in message
    news:...
    [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.
    Tintin, Sep 13, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page