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

Re: STDOUT and a PAR --gui executable

by crabbdean (Pilgrim)
on Apr 12, 2004 at 21:12 UTC ( #344525=note: print w/replies, xml ) Need Help??

in reply to STDOUT and a PAR --gui executable

Thanks Nuns and Monks for your help, it lead me down an interesting path ... and to finally a solution! :-)

The program discussed is a directory synchorniser which will be used for our laptop SOE at work to synchronise thier documents onto the server. I created two versions, one that synchronises directories to a TAR file and another to a ZIP file. Hence my reason for wanting to run it in silent mode, I didn't want the user knowing it was running. In reality I could have lived with a flash of the console to the screen as bbfu suggested in thier solution, but being a perfectionist of sorts I wanted an answer. fizbin's posted article was also very interesting. After testing and pondering the problem for about 2 hours here is what I did.

I compiled two versions of the program using the commands below. Note the difference in extensions I used on the programs.
pp --gui -o ZIPsync.exe pp -o
If you then run it at the command line *without* an extension like ZIPsync -v passing it my verbose paramater it outputs STDOUT to the commandline (because it picks up and runs with the ".com" version. Because I ran it from a commandline I already have a console so no problem, and the STDOUT is output. YAY!

If I go into the directory and double click the "exe" version it runs in --gui mode and hence no console at all. Beautiful!

But what about calling my EXE with *other* paramaters ? Well I created a shortcut to the EXE and put my paramaters into there. That also ran nicely! Additionally if you try to use the "verbose" paramater it just gets ignored because there is no STDOUT. A user in this case would be forced to specify the "log" paramater to gather output to a file.

There is one additional thing I came across which I'll try later when I get time. There is a module called Win32::Die which is only about ten lines of code. The description says "Win32::Die detects if your program was double-clicked, or run from a command line, and alters %SIG{__DIE__} appropriately." It would seem to me that its also possible to include similar code into my program and if it detects the program was double clicked to the automatically change the "verbose" paramater to set the "create a logfile" paramater, thereby defaulting my double-clicked EXE to create logs if verbose mode is requested. I'll try that one again later.

Thanks to all. So it seems its not impossible. There is always more than one way to skin an Operating System! :-)

The Funkster of Mirth
Programming these days takes more than a lone avenger with a compiler. - sam
RFC1149: A Standard for the Transmission of IP Datagrams on Avian Carriers

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (14)
As of 2016-10-26 17:37 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (345 votes). Check out past polls.