Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: retrieve the value of a system call in a non blocking mode

by taint (Chaplain)
on Dec 05, 2013 at 22:06 UTC ( [id://1065852]=note: print w/replies, xml ) Need Help??


in reply to Re: retrieve the value of a system call in a non blocking mode
in thread Do not display the command result in the console (updated)

Shouldn't that have been something more like
use strict; use warnings; system("echo test > myfile.txt" or die $!);
or how would we have known it wasn't possible to open/create myfile.txt. ;)

--Chris

UPDATE moved misplaced paren
#!/usr/bin/perl -Tw
eval {
I'm not completely useless, I can be used as a bad example.
}

Replies are listed 'Best First'.
Re^3: retrieve the value of a system call in a non blocking mode
by kcott (Archbishop) on Dec 06, 2013 at 11:31 UTC
    "UPDATE moved misplaced paren"

    You've removed what you originally posted so I don't know what you were attempting to fix (see "How do I change/delete my post?"). Regardless, what you now have is still not correct (I assume you didn't intend or die $! to be part of the shell command).

    See the examples in the system documentation for syntax and how to check for errors. You may also find the autodie pragma of interest.

    If you are unable to test your posted solutions, please clearly indicate this.

    Also, what you've shown as corrections later in this thread are also wrong (for the same reason). [Update (Clarification of "later in this thread"): I'm referring to "Re^4: retrieve the value of a system call in a non blocking mode" which is later than the post I'm replying to but appears physically earlier on this page.]

    -- Ken

      Greetings, kcott.

      Odd. It seemed to work for me. In fact, it was by virtue of testing it. That I discovered what I termed as being a HOMER moment above, was wrong.

      I'm afraid I was so embarrassed by the earlier example. I corrected it. Bad choice. I'd return it. But, now, I'm afraid I'll just mess up the order worse.

      So for the sake of clarity. I'll post my HOMER moment here:

      system("echo test > myfile.txt") or die $!;
      Sorry for messing things up. I'll just "suck up", and eat my mistakes in the future. Or better, take more care not make any. ;)

      Best wishes.

      --Chris

      Hey. I'm not completely useless. I can be used as a bad example.
      
Re^3: retrieve the value of a system call in a non blocking mode
by young_monk_love_perl (Novice) on Dec 05, 2013 at 22:22 UTC

    Hi Chris, the result of

    echo test > myfile.txt") or die $!;

    is to still display the command output in the console as usual, i cannot input anything exept SIGINT or SIGTERM, the screen display is dynamic but it doesn't create lines in the console except spaces and then freeze on the last screen when I kill the program. Maybe this precisions will be helpful.

    The .txt is created but it only contains two lines of spaces.

      D'OH! Had a bit of a HOMER moment there. :P

      What I should have put above was

      system("echo test > myfile.txt" or die $!); system("cat myfile.txt" or die $!);
      NOTE: the misplaced paren in my earlier post.
      sorry 'bout that.

      --Chris

      UPDATE: I should probably mention, that it might be more elegant to test the existence of the file myfile.txt before cattting it, rather than dieing. If interested. I'd post an example.
      Hey. I'm not completely useless. I can be used as a bad example.
      

        Sure, thank you taint I'm very interested by an example. Also are there some books you could recommend me about Perl ?

Re^3: retrieve the value of a system call in a non blocking mode
by VincentK (Beadle) on Dec 06, 2013 at 14:19 UTC

    Yep. You're right. I should have included the 'die' on the end of that statement. Thanks :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-03-28 18:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found