You don't specify in which environment you are working, so
I just presume you work in Perl's native environment UNIX,
and that you are using X-windows as your GUI environment.
(If you happen to work in a different environment, you've
wasted a lot of time, time I can't spend answering other
peoples questions.)
#!/usr/bin/perl
use strict;
use warnings;
my $pid = fork err die "Failed to fork: $!";
unless ($pid) {
exec "xterm" or die "Failed to exec: $!";
}
# $pid is the PID of 'xterm', but we want the PID of the shell
# that's run by the xterm.
# First we need to give the child time to spawn the shell.
sleep 1;
my $shell_pid;
open my $ps => "ps -ef |" or die "Failed to open pipe: $!\n";
while (<$ps>) {
my ($uid, $proc_pid, $proc_ppid) = split;
if ($proc_ppid && $proc_ppid eq $pid) {
$shell_pid = $proc_pid;
last;
}
}
# Open the pseudo-terminal of the shell, and print something.
open my $fh => "> /proc/$shell_pid/fd/1" or die "Failed to open termin
+al: $!";
print $fh "Hello!\n";
close $fh;
__END__
Abigail
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.