Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: perl scripting help

by kcott (Archbishop)
on May 29, 2021 at 02:02 UTC ( #11133242=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11133242]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2022-12-02 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?