Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

perl opening a new command line window

by bdalzell (Sexton)
on Feb 14, 2005 at 19:31 UTC ( #430901=perlquestion: print w/ replies, xml ) Need Help??
bdalzell has asked for the wisdom of the Perl Monks concerning the following question:

I have a perl ap that I run on an Amiga under Amiga OS. On the amiga i can open a new command line window with something called the con device and then I can send things like error messages to that window while still running perl from the original command line window

is there a similar way to open a new command line window under Unix and Windows

This is the line of code that will open the window on the Amiga (the stuff tot he right of con: is commands to the Amiga command line device which is called con:

open(WIN1,">con:30/40/400/100/MyWINDOW/AUTO/CLOSE")
and this will print something to it:

print WIN1 "hello WIN1\n";

Comment on perl opening a new command line window
Select or Download Code
Re: perl opening a new command line window
by Fletch (Chancellor) on Feb 14, 2005 at 19:40 UTC

    Presuming you mean "X11" when you ask about *NIX, the answer is probably "yes but not as simply". See man xterm for information on the -S option which allows you to open a pty and have xterm grab the other end. Any output you write to the pty will be displayed in the xterm (and theoretically one could also read input from it).

    Update: Oh yeah: IO::Pty may be of assistance getting a pty for this.

    Update: And while not exact code, see opening and writing to another xterm for the steps to take.

Re: perl opening a new command line window
by CloneArmyCommander (Friar) on Feb 14, 2005 at 19:59 UTC
    I do not know how to do it through Perl, it might be easily altered to work. When I am in bash I use something like:
    echo "Hello!" >/dev/tty2
    I hope my arrow is pointing the right direction :). This does not open the window, but it prints to an existing terminal session.

    I have not tried it yet, but you may be able to:
    open(TERMINAL,'>/dev/tty2'); . . .
    In case it is important, I am doing this on SuSE Linux Pro 8.2 :), it seems that tty12 is reserved for error messages.
Re: perl opening a new command line window
by BrowserUk (Pope) on Feb 14, 2005 at 20:01 UTC

    There is no way to have a single process connected to 2 cli windows simulaneously under Win32. You could create a gui style window with either native calls or one of the gui toolkits.

    It is possible to have multiple screen buffers associated with a single cli window. You can do this with Win32::Console. You then only need arrange for some key sequence to be recognised and trigger switching between the 2 or more screen buffers.

    You could take this a stage further and package it up using a tied filehandle to represent the "alternate console" so that you could use Perl's standard IO to write to the multiple consoles.

    If you don't like the idea of having to use a keysequence to allow you to view the various screens, you could take that a step further. Size the window to 160 x 48 and draw the different 'screens' in different portions of the one real screen. In fact, I frequently use an 8 point font in my console sessions which gives me a 250 x 120 screen, which could hold 15 80x24 sessions concurrently.


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.
Re: perl opening a new command line window
by wazoox (Prior) on Feb 14, 2005 at 22:05 UTC

    The easiest way I may think of is to redirect the output of your script to some file, and monitor its content with tail:

    term1% myscript.pl > /tmp/logfile term2% tail -f /tmp/logfile

    Even better, you can both have the output into the first windows and in the log file, with tee:

    term1% myscript.pl | tee /tmp/logfile

    IIRC there is a "CON:" device existing in windows, but I don't know what it is and what it's used for.

      Actually CON: is the "console device" for MS-DOS and Windows. Maybe some windows guru may learn us more about what tricks can be achieved with it....
      See some fun tricks using CON here :user input
Re: perl opening a new command line window
by Anonymous Monk on Feb 15, 2005 at 06:17 UTC
    how about a pipe?
    #!/usr/bin/perl system 'mknod thepipe p' unless -p 'thepipe'; if ( fork ) { system q(xterm -e 'exec < thepipe; cat'); } else { open F, '>thepipe'; select F; $|++; for (1..30) { print "and a $_ woot!\n"; sleep 1; } } unlink 'thepipe';
      depending upon your OS (Linux, Solaris, IRIX ...), you may use mkfifo instead of mknod ... p.
      Keep in mind that fifos may lock, or exit quite easily (the reader can't read anymore after the writer stops). however it'll save some disk space :)
      BTW, would it be possible to create an anonymous pipe (on the IO::File model perhaps?)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://430901]
Approved by Limbic~Region
Front-paged by friedo
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2014-10-22 04:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (112 votes), past polls