in reply to system function problem

I don't have "links" on my system so I can't try it, but you should check if your opens succede. This is how I would have written your program.
#!/usr/bin/perl -w use strict; my $file = 'temp.html'; open HTML, ">$file" or die "Damn: $file $!"; print HTML "<html><body>\n"; print HTML "<B> $_ </B>" while <>; print HTML "\n</body></html>\n"; close HTML or die $!; # close(STDIN); # links breaks if I close it explicitly die "System command failed $_" if system('links', $file) == -1;

Replies are listed 'Best First'.
Re^2: system function problem
by sk (Curate) on Sep 02, 2004 at 02:21 UTC

    Thanks Lidden!

    I did add the checks for open and close as per your suggestion. It does not change the end result. It is dumb on my part not to check for error on open (I shouldn't try to type code on the message box directly :)) I like your style on the system call! I have never used a die on close and that is also something that i should do going forward. Thanks again.

    Please let me know if you ever get a chance to test it on a machine with links.

    cheers

    SK

      Hi All,

      Something told me that I should check out links with pipes and I tried this.

      head myfile | links

      and i get the same problem that i had mentioned with my script. for some reason links does not like a pipe being open when it is called. In my script, The pipe should be done (i.e. no more data to feed) before it calls links but still it does not like that. I feel if we could close the pipe explicitly then it might help. is there a way to close that pipe explicitly? I am not sure how to do this because the user could send in a file name too, if they don't then it defaults to STDIN/Pipes i.e. i am using the <> handle.

      Thanks for your help!

      cheers

      SK

        closing and opening STDIN (by storing the handle in another place) did not work the way i expected. Someone in the elinks suggested that i do open(STDIN,"/dev/tty"); this worked great! I just thought I will close the loop on this. Thanks. -SK