Win32::Console with perl2exe -gui

P

PRSoftware

Hello,

I use perl2exe with the "-gui" option to create an "executable" (= a
single distribution file) without the DOS window.

But when my script has a problem, I can't have any report of the
problem.

I tried to use Win32::Console to open a new console to display the
problems but it doesn't work : the console window opens but the
standard output and input are not managed in this new console.

I tried a very simple program (myprog.pl) to check Win32::Console with
perl2exe :

use Win32::Console;
$CONSOLE = new Win32::Console;
$CONSOLE->Alloc;
print "hello\n";
<STDIN>;
sleep 10;

When I generate the .exe with "perl2exe myprog.pl" (without the -gui
option) all works fine : a console window opens, the text is displayed
and I have to press the Enter key to close the window.

But when I generate with "perl2exe -gui myprog.pl", the console window
appears but nothing is displayed and the standard input is not read
(the console is automatically closed after the 10 seconds sleep
delay).

I use :
- Win32::Console 0.031
- Perl 5.5.2 build 509
- Perl2Exe 5.03b
- Windows 98 SE.

Thanks for your help

PR
 
P

perl coder

PRSoftware said:
I use perl2exe with the "-gui" option to create an "executable" (= a
single distribution file) without the DOS window.

But when my script has a problem, I can't have any report of the
problem.
[del]

When I generate the .exe with "perl2exe myprog.pl" (without the -gui
option) all works fine : a console window opens, the text is displayed
and I have to press the Enter key to close the window.

But when I generate with "perl2exe -gui myprog.pl", the console window
appears but nothing is displayed and the standard input is not read
(the console is automatically closed after the 10 seconds sleep
delay).

I'm new to Windows programming, but from what I understand so far, there
are two different classes of binaries:

1. Pure GUI programs that don't have stdin/out/err file descriptors or
an associated command window (command.com or cmd.exe, depending on the
particular OS)

2. GUI or pure text programs that do have the standard file descriptors.
Such programs will spawn a command window if it wasn't launched from
one, and there is no way to prevent this (though the window can be
hidden from view immediately, but it will still flash momentarilly on
the screen).

I believe that the -gui option modifies some header bytes in the bundled
perl.exe to turn in into a pure GUI program (thus eliminating the
standard file descriptors).

DISCLAIMER: all or some of the above is possibly false! Like I said,
I'm new to the Windows world, and this is only what I've been able to
glean so far. I'd be very grateful if someone more knowledgeable in
these matters could either correct or confirm this info. ;-)

Anyway, instead of logging to a console, have you considered logging
your errors/debug info to a file instead? You can always open up a
shell window and read the log file at any time (just don't forget to set
autoflush on that filehandle so the output doesn't get buffered). Or
for that matter, you can always display the contents of that file in
your GUI program (frex, in a Tk::ROText window) if the data needs to be
easily accessible to end-users.
 
A

A. Sinan Unur

(e-mail address removed) (PRSoftware) wrote in
Hello,

I use perl2exe with the "-gui" option to create an "executable" (= a
single distribution file) without the DOS window.

But when my script has a problem, I can't have any report of the
problem.

I tried to use Win32::Console to open a new console to display the
problems but it doesn't work : the console window opens but the
standard output and input are not managed in this new console.

I tried a very simple program (myprog.pl) to check Win32::Console with
perl2exe :

use Win32::Console;
$CONSOLE = new Win32::Console;
$CONSOLE->Alloc;
print "hello\n";
<STDIN>;
sleep 10;

I will suggest actually reading the docs for Win32::Console. I had never
used it before and it didn't take much looking to figure out.

use strict;
use warnings;

use Win32::Console;

my $STDOUT = new Win32::Console(STD_OUTPUT_HANDLE);
$STDOUT->Alloc;
$STDOUT->Display;
$STDOUT->Write("Press any key to exit\n");

my $STDIN = new Win32::Console(STD_INPUT_HANDLE);
$STDIN->Alloc;

while( 1 ) {
my @event = $STDIN->Input;
last if $event[0] == 1;
sleep 1;
}
I use :
- Win32::Console 0.031
- Perl 5.5.2 build 509

Is that Perl version correct?

Sinan.
 
P

PRSoftware

A. Sinan Unur said:
(e-mail address removed) (PRSoftware) wrote in
Hello,

I use perl2exe with the "-gui" option to create an "executable" (= a
single distribution file) without the DOS window.

But when my script has a problem, I can't have any report of the
problem.

I tried to use Win32::Console to open a new console to display the
problems but it doesn't work : the console window opens but the
standard output and input are not managed in this new console.

I tried a very simple program (myprog.pl) to check Win32::Console with
perl2exe :

use Win32::Console;
$CONSOLE = new Win32::Console;
$CONSOLE->Alloc;
print "hello\n";
<STDIN>;
sleep 10;

I will suggest actually reading the docs for Win32::Console. I had never
used it before and it didn't take much looking to figure out.

use strict;
use warnings;

use Win32::Console;

my $STDOUT = new Win32::Console(STD_OUTPUT_HANDLE);
$STDOUT->Alloc;
$STDOUT->Display;
$STDOUT->Write("Press any key to exit\n");

my $STDIN = new Win32::Console(STD_INPUT_HANDLE);
$STDIN->Alloc;

while( 1 ) {
my @event = $STDIN->Input;
last if $event[0] == 1;
sleep 1;
}
I use :
- Win32::Console 0.031
- Perl 5.5.2 build 509

Is that Perl version correct?

Sinan.

Thanks a lot : your solution is very good : probably I didn't read the
doc very well ;-(

PR
 
P

PRSoftware

Oops, I think I cried for victory a bit too early ...

In fact, the code of A. Sinan Unur works fine if the "executable" is
launched in a command window (the output console opens and the text is
displayed).

But if it is directly launched by double-clicking the .exe in the
explorer, the output console is displayed but nothing is written in
.... Unfortunately it is the way my code is executed :-(((

Perhaps it is a problem with attributes of the created console but I
can't understand their use ...

What's the matter ???

Thanks

PR
 
A

A. Sinan Unur

(e-mail address removed) (PRSoftware) wrote in
Oops, I think I cried for victory a bit too early ...

In fact, the code of A. Sinan Unur works fine if the "executable" is
launched in a command window (the output console opens and the text is
displayed).

But if it is directly launched by double-clicking the .exe in the
explorer, the output console is displayed but nothing is written in
... Unfortunately it is the way my code is executed :-(((

It works if I compile it with the line:

perl2exe t.pl

Then, double-clicking on the resulting t.exe file opens a single console
window with the "Press any key to exit" message. Pressing any key results
in the console window being closed and the program terminates.

The whole thing runs very slowly, however. (Win XP-Pro, 1 Ghz Celeron,
512 Mb RAM).
Perhaps it is a problem with attributes of the created console but I
can't understand their use ...

What's the matter ???

I do not know. perl2exe is commercial software. Have you asked
IndigoStar?
 
P

PRSoftware

Effectively, if you "compile" your code with the command

perl2exe t.pl

it works but if you compile with the command

perl2exe -gui t.pl

the command window is opened but nothing is written in (at least on my
PC) and the input doesn't function anymore.

Did you try your code with the "-gui" option ?

Thanks for your help

PR
 
P

Paul Lalli

Effectively, if you "compile" your code with the command

perl2exe t.pl

it works but if you compile with the command

perl2exe -gui t.pl

the command window is opened but nothing is written in (at least on my
PC) and the input doesn't function anymore.

Did you try your code with the "-gui" option ?

.... which is exactly what's supposed to happen. The whole point of the
-gui option is to disable the console window from appearing, so the
program will just run with a GUI. (of course, in your code, you
override this by explicitly calling a Win32::Console). If you don't want
that behavior, why are you adding the -gui option?

Paul Lalli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top