You might try forking. This works, but as soon as mc is exited, the spawned xterm closes. Instead of mc, you may be able to write a custom looping program, that accepts input from the xterm, but never ends without a Control c or something. That would be your command processor. Its just a hack, you are almost always better off using an IPC module.
#!/usr/bin/perl use warnings; use strict; $|++; #You could fork off a child and call exec from that child. #Then you could use the PID from fork to call kill. Thus: my $kidpid; if ( !defined( $kidpid = fork() ) ) { #fork returned undef, so failed die "Cannot fork: $!"; } elsif ( $kidpid == 0 ) { exec("xterm -e mc &"); # xterm stays open until mc is exited # or a custom command processor } # this is all executed in the parent #... print "pid $kidpid\n"; sleep 5; # kill -9, $kidpid; print "hit Enter to exit main script\n"; <>; exit;
Here is an example of a program you could use as a command processor, for the xterm. It does have one drawback in that it dosn't run your initial $setup command, BUT you could have the command processor run $setup as it's first command to bash, then it would hang around in the while loop for more commands, and the xterm would maintain existence.
#!/usr/bin/perl use warnings; use strict; use IPC::Open3; use IO::Select; #interface to bash my $pid = open3(\*WRITE, \*READ,\*ERROR,"bash"); #if \*ERROR is false, STDERR is sent to STDOUT my $selread = new IO::Select(); my $selerror = new IO::Select(); $selread->add(\*READ); $selerror->add(\*ERROR); # may not be best use of IO::Select, but it works :-) my($error,$answer)=('',''); while(1){ print "Enter expression for bash, i.e. date\n"; chomp(my $query = <STDIN>); #send query to bash print WRITE "$query\n"; #timing delay needed tp let bash output select(undef,undef,undef,.01); #see which filehandles have output if($selread->can_read(0)){print "ready->read\n"} if($selerror->can_read(0)){print "ready->error\n"} #get any error from bash sysread(ERROR,$error,4096) if $selerror->can_read(0); if($error){print "\e[1;31m ERROR-> $error \e[0m \n"} #get the answer from bash sysread(READ,$answer,4096) if $selread->can_read(0); if($answer){print "$query = $answer\n"} ($error,$answer)=('',''); } waitpid($pid, 1); # It is important to waitpid on your child process, # otherwise zombies could be created.

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: Running CMD in perl invoked xterm by zentara
in thread Running CMD in perl invoked xterm by Ohad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.