in reply to perl scripting help
G'day ejm20,
Welcome to the Monastery.
I'm not entirely sure what your ultimate goal is here. You wrote "create a perl script in bash" which I find confusing. It seems to me that you could put your bash commands in a bash script and run that from an xterm (or equivalent).
Having said that, and based on the code you've managed so far, perhaps you're after something like this:
#!/usr/bin/env perl use strict; use warnings; use autodie ':all'; my @commands = ( 'set -vx', "cd $ENV{HOME}", 'date', 'pwd', '/usr/bin/bash -i', ); system qw{/usr/bin/xterm -e}, join ';', @commands;
When I run that, it pops up an xterm window containing:
+ cd /home/ken + date Sat, 29 May 2021 10:44:54 + pwd /home/ken + /usr/bin/bash -i ken@titan ~ $
I can now type more commands into that xterm window. It shuts down normally with exit or Ctrl-D.
One thing to note is that the Perl script (which I called pm_11133222_xterm.pl) will block until the xterm window closes. If that's an issue, you can run it in the background.
This starts the xterm and returns my normal prompt:
ken@titan ~/tmp $ ./pm_11133222_xterm.pl & [1] 2182 ken@titan ~/tmp $
After closing the xterm and hitting enter:
ken@titan ~/tmp $ [1]+ Done ./pm_11133222_xterm.pl ken@titan ~/tmp $
You may, of course, already know how to do that.
I didn't think I had gnome-terminal but apparently I do. I'm running Cygwin 3.2.0 (on Win10) so I no doubt got it via some package. I don't have a manpage for it; I found gnome-terminal(1); it says "gnome-terminal is designed to emulate the xterm program ..." but simply replacing xterm with gnome-terminal resulted in various warning and error messages. I got it to run by replacing the last line of script above with:
system qw{/usr/bin/gnome-terminal -- /usr/bin/bash -c}, join ';', @com +mands;
This now popped up a window with the same initial content as the xterm window described above; subsequent interaction also worked the same. There were, however, two differences: the Perl script did not block; and, I got this warning:
** (gnome-terminal:2292): WARNING **: Error retrieving accessibility b +us address: org.freedesktop.DBus.Error.NoReply: Message recipient dis +connected from message bus without replying
An internet search for that message got quite a few hits. Here's a couple of workarounds to remove the warning:
$ NO_AT_BRIDGE=1 ./pm_11133222_gnome.pl $ ./pm_11133222_gnome.pl 2> /dev/null
As I don't use gnome-terminal — fairly obviously as I only just found that I had it — I wasn't particularly interested in delving into this further. If you encounter the same problem and identify a genuine fix (as opposed to a workaround) please share as it may be useful to others in the future.
— Ken
|
---|
Replies are listed 'Best First'. | |
---|---|
A reply falls below the community's threshold of quality. You may see it by logging in. |