in reply to Do not display the command result in the console (updated)

Hi young_monk_love_perl

Is something like this what you want?

use strict; use warnings; system("echo test > myfile.txt");

Replies are listed 'Best First'.
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
    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.
    }
    
      "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.
        

      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.
        

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