Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Run a shell command in a new terminal from a perl script?

by ironside (Acolyte)
on Jan 31, 2012 at 22:01 UTC ( #951081=perlquestion: print w/replies, xml ) Need Help??
ironside has asked for the wisdom of the Perl Monks concerning the following question:


I am trying to write a perl script that will run a command in a new terminal.

I found code to open a new terminal from my script but it will not run the command when it opens. Does anyone know how I can achieve this?

Thanks in advance.


I would like this script to open a new Gnome window.

When I run the following command from the command line, it does what I am trying to achieve: gnome-terminal -x sh -c "ls|less"

Is there any way of getting this command to run from with in a perl script?

  • Comment on Run a shell command in a new terminal from a perl script?

Replies are listed 'Best First'.
Re: Run a shell command in a new terminal from a perl script?
by Eliya (Vicar) on Jan 31, 2012 at 23:34 UTC

    Which platform?  On Unix you can (for example) do something like this

    system q/xterm -e perl -le 'print "line $_" for 1..20; <>'/;

    which would print 20 ines in a new xterm, and wait for you to press enter to close the terminal again.  The -e option specifies the command to run in the xterm (some perl, here).  Virtually any other terminal has similar facilities.

    Is that what you are trying to do?

      I am running this script on Ubuntu

      The script I am writing pulls a few command line programs together. I want to be able to have one of the programs run in a new terminal while my main program continues to run in the first terminal.

        It can be done, but it's tricky. Here's a script that I wrote to test Module::Install and ExtUtils::MakeMaker.
        #!/usr/bin/perl -l use strict; use warnings; $|=1; open STDOUT, '>-'; system("xterm -e cpan -ft Module::Install &"); close STDOUT; use CPAN; CPAN::Shell->test("ExtUtils::MakeMaker");

        Update: The script requires a lot of RAM, so it may or may not work for you. Try some other commands until it works.

        Update: This will probably work better for you.
        #!/usr/bin/perl -l use strict; use warnings; $| =1; open STDOUT, '>-'; system("du /usr/lib/perl5 &"); close STDOUT; open STDOUT, '>-'; system("xterm -e du /usr/lib/perl5 &"); close STDOUT;
Re: Run a shell command in a new terminal from a perl script?
by Anonymous Monk on May 11, 2017 at 16:49 UTC
    #!/usr/bin/perl use strict; use warnings; system('gnome-terminal -x sh -c "ls|less"');
    is this what u want . sweet and simple (p.s i m a new to this things)
      can you explain more about the code written

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://951081]
Approved by planetscape
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2018-05-23 04:08 GMT
Find Nodes?
    Voting Booth?