Stuart
Stuart

Reputation: 1773

Run a shell command through Perl in a specific terminal

First off, I am pretty new to Perl so I may be missing something obvious. This is not the typical "I want to run a shell command through Perl" question.

I don't want to capture all of the shell output. I have a program/script that intelligently writes to the terminal. I didn't write it and don't know how it all works, but it seems to move the view to the appropriate place after printing some initialization, then erase previous terminal output and write over it (updates) until it finally completes. I would like to call this from my perl script rather than printing everything to a file to grab it after, since printing to a file does not keep the intelligence of the printout.

All I need to do is:

  1. open an xterm in my perl script
  2. make a system call in that terminal
  3. have that terminal stay up until I manually exit it

Can I do this in perl?

Thanks.

Upvotes: 2

Views: 4064

Answers (2)

Gilles Quénot
Gilles Quénot

Reputation: 185851

Try doing this by example :

#!/usr/bin/env perl

use strict; use warnings;
use autodie;

open my $term, '| xterm -hold -e $(</dev/stdin)';
foreach my $dir (qw|/etc /usr /home|) {
    print $term "ls $dir\n"; # do anything else you'd like than "ls $dir" here
}
close $term;

Upvotes: 2

ajk
ajk

Reputation: 1055

system 'xterm', '-hold', '-e', $program;

where $program is the terminal-aware program you want to run.

-hold causes xterm to stay open after the program exits, waiting for you to close it manually.

-e specifies the program or command line to run. It and its argument must appear last on the xterm command line.

Upvotes: 2

Related Questions