rojam74 has asked for the wisdom of the Perl Monks concerning the following question:

Hello monkettes and monks- I'm trying to run a small tcl application which opens an Xwindow for a split second to do some work...from within a perl script. I've tried calling this app directly from within my perl code using system($cmd), and backticks... but neither approaches seem to allow the Xwindow to open. What do I need to do to allow this called program to open an Xwindow? *note- i'm running the perl script from within a valid X-window, and running the tcl script directly works from the same x-window. Thanks- John

Replies are listed 'Best First'.
Re: run X-application via system call?
by randyk (Parson) on Oct 12, 2005 at 21:42 UTC
    Are you wanting to open up an xterm window to run this? If so, try the following:
    use strict; use warnings; my $title = 'xterm example'; my $msg = 'press any key to continue ...'; my $exec = 'ls'; my $cmd = qq{xterm -T "$title" -e "$exec && read -p '$msg' -n1"}; my $rc = qx{$cmd};
Re: run X-application via system call?
by EvanCarroll (Chaplain) on Oct 12, 2005 at 20:47 UTC
    You will need to have your environmental DISPLAY variable set properly, and the ~/.xsession of who ever started X.


    Evan Carroll
    www.EvanCarroll.com
Re: run X-application via system call?
by samizdat (Vicar) on Oct 13, 2005 at 12:49 UTC
    As an expansion of randyk's posting, here are a few more variants:

    Run without user input:
    system("xterm -e bash --rcfile /path/to/my/file.pl") && die "XTERM FAIL: $!\n";
    Run and continue main prog operation:
    system("xterm -e bash --rcfile /path/to/my/file.pl &") && die "XTERM FAIL: $!\n";
    Execute your prog, fire off another command, and leave the xterm open with a new shell:
    system("xterm -e bash --rcfile /path/to/my/file.pl -i -c \"$acommandst +ringtoexec && exec bash\" &") && die "XTERM FAIL: $!\n";
    This was originally designed as part of a large shell script (mentioned in the thread Just hammering nails...). In the original rcfile, numerous ENV variables are set so that the new shell has what it needs in terms of PATHs and settings in order to run. The third variant allows both an rcfile and a command-line string to be executed and the window to remain open for further processing, an extremely powerful combination. I'm definitely not a shell script guru, but this was fun to write. The --rcfile option is bash2-specific, as are the interpretation of the -i and -c switches, but the final shell left open can be any shell or shell-like program, leaving you with three possible execution points.