Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

I want to call a special xterm to execute "ls" command in a perl script

by Anonymous Monk
on Aug 21, 2013 at 14:41 UTC ( #1050361=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I have a bother thing, I try my best to find answer for a whole day to solve it.

My demand like thing, I want to call a xterm to execute the "ls" command. I find monks have follow idea:

my $pid= fork(); unless($pid){ exec "xterm -e "ls > log"; }

but our xterm is a special command that it use "-e" alreay, that is say we can't use the method above(exec "xterm -e "ls > log";)

.

1.I want to use pipe, socket, background process and so on to realize it, but I have no idea.

2.for this case, mustn't the xterm called pop up, and it must run as ground process?

Comment on I want to call a special xterm to execute "ls" command in a perl script
Download Code
Re: I want to call a special xterm to execute "ls" command in a perl script
by derby (Abbot) on Aug 21, 2013 at 14:58 UTC

    Why the heck do you want to go to all that bother. Why not use opendir, readdir, etc. Or just system with ls. There's no need to bring xterm into the mix.

    -derby
      Hi derby, I'm the one you replied. the "ls" is only a simple exaple. the real case is that I want to open a special xterm with "TBTerm" cmd, and in this special xterm have a special cmd named "vst".. so the full and simplified thing I want to do is: in a perl script,firt open a new another xterm, and execute a command in the new xterm, and return the result of this cmd to script.

        Perl cannot normally control other applications' terminals, so you'll have your application to fork, then run the child process under xterm, then use Expect module to pass the "vst" command to the "TBTerm" program. Read perlop about quoting operators if you don't know how to quote your command properly.

        Use something like this to run your application under xterm:

        unless (-t STDIN) { # check whether STDIN is a terminal exec (qw/xterm -e/,$0); # assuming that your perl file is executab +le }
        Do you really need to spawn another xterm? If not, you can simplify your application and avoid coping with returning text data from forked child process (read pipe, by the way), since Expect creates a virtual terminal (not visible as a graphical window, though) to run your application into.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1050361]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2014-10-22 10:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (115 votes), past polls