|
|
 |
 |
 |
 |
Perl Programming Language
|
 |
 |
 |
 |
 |
 |
 |
 |
Illegal seek
Hello, Sometimes I get the error message: "Illegal seek". An example of this is when I have the following in a Perl script: my $run = "touch abc"; `$run` || print STDERR "Command '$run' failed: $! \n"; The error message I get is: Command 'touch abc' failed: Illegal seek Yet, the file 'abc' is created/updated. But when $run = "ls -las", I don't get this error message. Does anyone know why I am getting this error? Is there a better way to accomplish the same thing? Eric
>>>>> "E" == Eric <ecarl @vmware.com> writes: E> my $run = "touch abc"; E> `$run` || print STDERR "Command '$run' failed: $! \n"; why are you using backticks when you don't want the output? the return value of `` IS NOT an error message. E> The error message I get is: E> Command 'touch abc' failed: Illegal seek you are likely getting some other error message left in $! as the backticks always worked. any error touch makes would not be return in the backticks but in $@. E> Does anyone know why I am getting this error? Is there a better way to E> accomplish the same thing? perldoc -f utime no reason to fork out as perl has it builtin. uri -- Uri Guttman ------ u@stemsystems.com -------- http://www.stemsystems.com --Perl Consulting, Stem Development, Systems Architecture, Design and Coding- Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
On Apr 13, 2:24 pm, Uri Guttman <u@stemsystems.com> wrote:
> >>>>> "E" == Eric <ecarl @vmware.com> writes: > E> my $run = "touch abc"; > E> `$run` || print STDERR "Command '$run' failed: $! \n"; > why are you using backticks when you don't want the output? the return > value of `` IS NOT an error message. > E> The error message I get is: > E> Command 'touch abc' failed: Illegal seek > you are likely getting some other error message left in $! as the > backticks always worked. any error touch makes would not be return in > the backticks but in $@. > E> Does anyone know why I am getting this error? Is there a better way to > E> accomplish the same thing? > perldoc -f utime > no reason to fork out as perl has it builtin. > uri > -- > Uri Guttman ------ u@stemsystems.com --------http://www.stemsystems.com > --Perl Consulting, Stem Development, Systems Architecture, Design and Coding- > Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Thanks for your response. We do in fact want the response, at least when in verbose mode. For clarity reasons, I didn't include all of the code. As far as the 'touch' command goes, this is not the actual command we are running. I changed it to this for simplicity reasons. Having said this, I still am not clear on why I am getting the error message with some commands but not others. Eric
"Eric" <ecarl @vmware.com> writes: > On Apr 13, 2:24 pm, Uri Guttman <u @stemsystems.com> wrote: >> >>>>> "E" == Eric <ecarl @vmware.com> writes: >> E> my $run = "touch abc"; >> E> `$run` || print STDERR "Command '$run' failed: $! \n"; >> why are you using backticks when you don't want the output? the return >> value of `` IS NOT an error message. >> E> The error message I get is: >> E> Command 'touch abc' failed: Illegal seek >> you are likely getting some other error message left in $! as the >> backticks always worked. any error touch makes would not be return in >> the backticks but in $@. > Having said this, I still am not clear on why I am getting the error > message with some commands but not others.
For a command that produces no output when it succeeds, such as touch, the value of `` is *supposed* to be undef. For those commands, you're printing an error message because `` is undef, when in fact there was no error. Other commands normally produce output, but print a message to STDERR on failure, and nothing to STDOUT. For *those* commands, capturing nothing with `` would indicate failure. So like Uri said, the value returned by `` is not a reliable means of error detection. You need to check $@ to detect errors with ``. sherm-- -- Web Hosting by West Virginians, for West Virginians: http://wv-www.net Cocoa programming in Perl: http://camelbones.sourceforge.net
On Apr 13, 3:31 pm, Sherm Pendley <spamt@dot-app.org> wrote:
> "Eric" <ecarl @vmware.com> writes: > > On Apr 13, 2:24 pm, Uri Guttman <u @stemsystems.com> wrote: > >> >>>>> "E" == Eric <ecarl @vmware.com> writes: > >> E> my $run = "touch abc"; > >> E> `$run` || print STDERR "Command '$run' failed: $! \n"; > >> why are you using backticks when you don't want the output? the return > >> value of `` IS NOT an error message. > >> E> The error message I get is: > >> E> Command 'touch abc' failed: Illegal seek > >> you are likely getting some other error message left in $! as the > >> backticks always worked. any error touch makes would not be return in > >> the backticks but in $@. > > Having said this, I still am not clear on why I am getting the error > > message with some commands but not others. > For a command that produces no output when it succeeds, such as touch, the > value of `` is *supposed* to be undef. For those commands, you're printing > an error message because `` is undef, when in fact there was no error. > Other commands normally produce output, but print a message to STDERR on > failure, and nothing to STDOUT. For *those* commands, capturing nothing > with `` would indicate failure. > So like Uri said, the value returned by `` is not a reliable means of error > detection. You need to check $@ to detect errors with ``. > sherm-- > -- > Web Hosting by West Virginians, for West Virginians:http://wv-www.net > Cocoa programming in Perl:http://camelbones.sourceforge.net- Hide quoted text - >
Hello, Thank you both for your responses. I tried this, but got the same error message. Eric
Eric wrote: > Sometimes I get the error message: "Illegal seek". An example of this > is when I have the following in a Perl script: > my $run = "touch abc"; > `$run` || print STDERR "Command '$run' failed: $! \n"; > The error message I get is: > Command 'touch abc' failed: Illegal seek > Yet, the file 'abc' is created/updated. > But when $run = "ls -las", I don't get this error message. > Does anyone know why I am getting this error? Is there a better way to > accomplish the same thing?
Yes, you want to do this instead: my @args = ( 'touch', 'abc' ); system( @run ) == 0 or print STDERR "Command '@run' failed: $? \n"; John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall
Uri Guttman wrote: >>>>>>"E" == Eric <ecarl @vmware.com> writes: > E> my $run = "touch abc"; > E> `$run` || print STDERR "Command '$run' failed: $! \n"; > why are you using backticks when you don't want the output? the return > value of `` IS NOT an error message. > E> The error message I get is: > E> Command 'touch abc' failed: Illegal seek > you are likely getting some other error message left in $! as the > backticks always worked. any error touch makes would not be return in > the backticks but in $@.
I think you mean $? instead of $@. John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall
>>>>> "E" == Eric <ecarl @vmware.com> writes: E> On Apr 13, 3:31 pm, Sherm Pendley <spamt@dot-app.org> wrote: >> >> So like Uri said, the value returned by `` is not a reliable means >> of error detection. You need to check $@ to detect errors with ``. E> Thank you both for your responses. I tried this, but got the same E> error message. and with what code? we can't debug /dev/null scripts. as for your changing the command as it isn't touch, that is not fair to us either. if you want help you first have to show some real code with a real problem. touch isn't real and your use of backticks is very wrong as you have shown it. uri -- Uri Guttman ------ u@stemsystems.com -------- http://www.stemsystems.com --Perl Consulting, Stem Development, Systems Architecture, Design and Coding- Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
>>>>> "JWK" == John W Krahn <some @example.com> writes: JWK> Uri Guttman wrote: >>>>>>> "E" == Eric <ecarl@vmware.com> writes: >> E> my $run = "touch abc"; E> `$run` || print STDERR "Command '$run' failed: $! \n"; >> >> why are you using backticks when you don't want the output? the return >> value of `` IS NOT an error message. >> E> The error message I get is: >> E> Command 'touch abc' failed: Illegal seek >> >> you are likely getting some other error message left in $! as the >> backticks always worked. any error touch makes would not be return in >> the backticks but in $@. JWK> I think you mean $? instead of $@. probably. i always confuse those and either rtfm or find other code where i used the right one. :) in general i don't use backticks too often anyway. i know what perl has builtin and i use backticks for their output, not success/failure results. uri -- Uri Guttman ------ u@stemsystems.com -------- http://www.stemsystems.com --Perl Consulting, Stem Development, Systems Architecture, Design and Coding- Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Eric schreef: > For > clarity reasons, I didn't include all of the code.
:( -- Affijn, Ruud "Gewoon is een tijger."
On Apr 14, 4:10 am, "Dr.Ruud" <rvtol+n@isolution.nl> wrote: > Eric schreef: > > For > > clarity reasons, I didn't include all of the code. > :( > -- > Affijn, Ruud > "Gewoon is een tijger."
Sorry for not following the group protocal. Here is the code. The launch.pl file runs the mountDefaultBuild.pl script. =========================================== File: launch.pl: ---------------- #! /usr/bin/perl -w use strict; my $script = "/usr/local/mountDefaultBuild.pl"; `$script` || print STDERR "Command '$script' failed: $?"; File: mountDefaultBuild.pl -------------------------- #! /usr/bin/perl -w use strict; use Fcntl qw(:DEFAULT :flock); my $execute = "/usr/sbin/exportfs -r"; my $umount = "umount /networkinstall/default"; my $mount = "mount -o loop /networkinstall/tmp/build.iso / networkinstall/default"; unless (open SEMAPHORE, "> /tmp/mounts.lock") { print STDOUT "unexpected problem opening /tmp/mounts.lock\n"; }
flock SEMAPHORE, Fcntl::LOCK_EX; `$execute` || print STDERR "Command '$execute' failed: $?\n"; `$umount` || print STDERR "Command '$umount' failed: $?\n"; `$mount` || print STDERR "Command '$mount' failed: $?\n"; `$execute` || print STDERR "Command '$execute' failed: $?\n"; close SEMAPHORE; =========================================== Thanks. Eric
|
 |
 |
 |
 |
|