Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

comment on

( #3333=superdoc: print w/replies, xml ) Need 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 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 $ ./ & [1] 2182 ken@titan ~/tmp $

After closing the xterm and hitting enter:

ken@titan ~/tmp $ [1]+ Done ./ 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 ./ $ ./ 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

In reply to Re: perl scripting help by kcott
in thread perl scripting help by ejm20

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2023-01-30 21:50 GMT
Find Nodes?
    Voting Booth?

    No recent polls found