Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Using backticks with (mount):

by JP Sama (Hermit)
on Jul 18, 2000 at 09:10 UTC ( #22947=perlquestion: print w/replies, xml ) Need Help??

JP Sama has asked for the wisdom of the Perl Monks concerning the following question:

While doing a CGI file that mount's and umount's devices in a linux computer, I tried to use:
$example = `mount`; $example = $! if $!; print $example;
But the answer to the "print $example;" was an "illegal check" message!
I looked really hard, but I didn't find the error, or something that would cause the error message.

My major doubt is that the "cgi" is working errr... "properly", but the error message insists to appear!
So, i did the test:
$example = `mount`; $error = $! if $!; print $example; print $error;
And the "print $example;" returned the expected answer, but the "print $error;" returned the same "illegal check" message.

If anyone could help me to solve this problem, I'ld be really gratefull!
Thanks a lot!

- jpsama

Replies are listed 'Best First'.
Re: Using backticks with (mount):
by mikfire (Deacon) on Jul 18, 2000 at 16:35 UTC
    This is nothing abnormal - you are checking the wrong variable. You should really check $? before looking at $!.

    Please, open your perldocs to perlvar and read

    $! If used in a numeric context, yields the current value of errno, with all the usual caveats. (This means that you shouldn't depend on the value of $! to be anything in particular unless you've gotten a specific error return indicating a system error.)
    Note the parenthetical part. There is also a long section in perlvar ( under the title Error Indicators ) that may help you out a little.

    mikfire

      Dude! Great call! And also this, from perlvar:
      Finally, $? may be set to non-0 value if the external program /cdrom/install fails. Upper bits of the particular value may reflect specific error conditions encountered by this program (this is program-dependent), lower-bits reflect mode of failure (segfault, completion, etc.). Note that in contrast to $@, $!, and $^E, which are set only if error condition is detected, the variable $? is set on each wait or pipe close, overwriting the old value.
      But it still doesn't explain why $! would start up with Illegal Seek...

      #!/home/bbq/bin/perl
      # Trust no1!
        Why shouldn't it? The value is indeterminate when no error has occurred. You are seeing, effectively, /dev/random. There is no deeper mystery here, to my understanding.

        mikfire

Re: Using backticks with (mount):
by btrott (Parson) on Jul 18, 2000 at 10:16 UTC
    Take a look at this thread: Illegal seek from Find::File. The crux of the matter is, it's probably not something to be concerned about. I get an "Illegal Seek" error in $! when I do *any* call in backticks.

    If the mount is correct, then I'd say don't worry about it.

RE: Using backticks with (mount):
by BBQ (Deacon) on Jul 18, 2000 at 09:13 UTC
    On a side note, I work with jp_sama, and the error message was Illegal Seek instead of Illegal Check. I couldn't figure this one out either... Why would the backticks be producing $OS_ERROR while still returning the expected result?

    Shouldn't they do one or the other? Backticking is getting on my nerves as well... Maybe find a better way to do with through system()?

    #!/home/bbq/bin/perl
    # Trust no1!
RE: Using backticks with (mount):
by Petruchio (Vicar) on Jul 18, 2000 at 16:13 UTC
    I ran your program, and the value I got for $! was "no such file or directory". So I tried this program: #!/usr/bin/perl print $!; Sure enough, same error message. Apparently $! starts off defined; I don't know why, and I'd noticed before. So you might just want to start things off with: undef $!;
      I was unsure how this cgi formatted posts; apparently I should have included html tags. If only we could preview comments! Let me try again...

      I ran your program, and the value I got for $! was "no such file or directory". So I tried this program:

      #!/usr/bin/perl

      print $!;

      Sure enough, same error message. Apparently $! starts off defined; I don't know why, and I'd noticed before. So you might just want to start things off with: undef $!;

Re: Using backticks with (mount):
by JP Sama (Hermit) on Jul 18, 2000 at 22:10 UTC
    But, the return for:
    $error = $! if $!; print $error;
    should be the message error, but if an error occurred during the process, right?

    At least, this was my intention...

    btw, I am looking in the perlvar, as sugested, and I couldn't solve my doubt yet.

    well, thank you! =)

    -jpsama
      In brief-

      Don't look at the value of $! in the general case. Structure your error checking to only look at $! after detecting an error by other means. Usually that means after a call fails.

      Paris Sinclair    |    4a75737420416e6f74686572
      pariss@efn.org    |    205065726c204861636b6572
      I wear my Geek Code on my finger.
      

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://22947]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2022-08-08 01:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?