Valhalla Legends Archive

Programming => General Programming => Java Programming => Topic started by: Tuberload on January 22, 2004, 04:07 PM

Title: Making a program run in the background with Java.
Post by: Tuberload on January 22, 2004, 04:07 PM
I find it really annoying that the command prompt is in my taskbar when I create a program I just want running in the background. I have been searching for sometime now for a way to do this in java but haven't found one, or any info on whether or not this is even possible.
Title: Re:Making a program run in the background with Java.
Post by: Kp on January 22, 2004, 04:17 PM
Well, the somewhat hackish way that I think should work (albeit requiring non-Java code) : write something to spawn the java interpreter for you, without a console of its own.  It'd be totally invisible, though.  Alternately, you could redirect stdin/stdout/stderr beforehand to pipes controlled by your process, which could then provide an alternate UI for it (perhaps add a systray icon and pop up a tooltip if the Java interpreter prints anything "interesting").  The possibilities are endless (once you give up on Java ;)).
Title: Re:Making a program run in the background with Java.
Post by: Tuberload on January 22, 2004, 04:20 PM
Quote from: Kp on January 22, 2004, 04:17 PM
Well, the somewhat hackish way that I think should work (albeit requiring non-Java code) : write something to spawn the java interpreter for you, without a console of its own.  It'd be totally invisible, though.  Alternately, you could redirect stdin/stdout/stderr beforehand to pipes controlled by your process, which could then provide an alternate UI for it (perhaps add a systray icon and pop up a tooltip if the Java interpreter prints anything "interesting").  The possibilities are endless (once you give up on Java ;)).

I never thought of that. I guess I will have to sit down and figure out how to do that in C++.

I know, I know... I am working on learning C/C++, but I like Java. For the first time I am actually understanding programming concepts and theories. Not to say this is because of Java, but Java is the language I have been learning with recently so I am sticking with it. From here I will move on to bigger and better things.
Title: Re:Making a program run in the background with Java.
Post by: Kp on January 22, 2004, 04:25 PM
Look into CreateProcess, in particular the creation flags.  You'll want to create the java process detached from the console.  If you go for having a systray icon, look into Shell_NotifyIcon and the TaskbarCreated window message (which has a dynamically assigned ID you can get from RegisterWindowMessage).
Title: Re:Making a program run in the background with Java.
Post by: iago on January 22, 2004, 05:23 PM
I would recommend a program called, "Window Hider".  I know I posted a thread about this once, but to save time you can get it  at http://www.twilightutilities.com.  

The way I prefer to do it, however, is by typing:
"java MyProgram &"
Title: Re:Making a program run in the background with Java.
Post by: Chopz on January 27, 2004, 07:50 PM
Thanks iago
Title: Re:Making a program run in the background with Java.
Post by: goofy-rhino on June 27, 2004, 01:21 PM
'javaw' runs on win32 without a console popping up

run

javaw mypackage.MyClass
Title: Re:Making a program run in the background with Java.
Post by: iago on June 27, 2004, 04:54 PM
Quote from: goofy-rhino on June 27, 2004, 01:21 PM
'javaw' runs on win32 without a console popping up

run

javaw mypackage.MyClass

oops, yeah, I know that now, but I forgot about this topic :)
Title: Re:Making a program run in the background with Java.
Post by: Tuberload on June 27, 2004, 05:07 PM
Ah a much better solution. I was creating a wrapper executable in C++ to load the Java classes in the background.