How can Perl’s system() print the command that it’s running?

Question :

How can Perl’s system() print the command that it’s running?,

Answer :

In Perl, you can execute system commands using system() or “ (backticks). You can even capture the output of the command into a variable. However, this hides the program execution in the background so that the person executing your script can’t see it.

Normally this is useful but sometimes I want to see what is going on behind the scenes. How do you make it so the commands executed are printed to the terminal, and those programs’ output printed to the terminal? This would be the .bat equivalent of “@echo on”.

Read More  Fixed vs. variable frame rates in games: what is best, and when?

,

I don’t know of any default way to do this, but you can define a subroutine to do it for you:

sub execute {      my $cmd = shift;      print "$cmdn";      system($cmd);  }    my $cmd = $ARGV[0];  execute($cmd);  

And then see it in action:

pbook:~/foo rudd$ perl foo.pl ls  ls  file1   file2   foo.pl  

That’s the answer How can Perl’s system() print the command that it’s running?, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Read More  Add multiple window.onload events

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you