www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to avoid the console from apearing.

reply John Connors <JohnConnors mailinator.com> writes:
Hi.

This is my entire program:

import std.process: system;

int main(string[] argv)
{
	return system(r"bin\someprogram.exe");
}

It works but a console (from my program) apears while someprogram.exe is
running. I've read that some optlink switches are needed to make the console
disapear. Tried the following (which I found in DM FAQ), but don't seem to work:

dmd -L/exet:nt/su:windows loader.d resource.res

The console keeps appearing.

Do you care to give me the correct switches?

Thanks
Aug 17 2010
next sibling parent reply Michal Minich <michal.minich gmail.com> writes:
On Tue, 17 Aug 2010 21:40:02 +0000, John Connors wrote:

 Hi.
 
 This is my entire program:
 
 import std.process: system;
 
 int main(string[] argv)
 {
 	return system(r"bin\someprogram.exe");
 }
 
 It works but a console (from my program) apears while someprogram.exe is
 running. I've read that some optlink switches are needed to make the
 console disapear. Tried the following (which I found in DM FAQ), but
 don't seem to work:
 
 dmd -L/exet:nt/su:windows loader.d resource.res
 
 The console keeps appearing.
 
 Do you care to give me the correct switches?
 
 Thanks

this example does not shows console. Maybe you can simplify it. http://digitalmars.com/d/2.0/windows.html in step 3 you need to crate mydef.def file and give it as an argument to compiler. you will probably not need, but complete docs are here http://www.digitalmars.com/ctg/ctgDefFiles.html http://www.digitalmars.com/ctg/win32programming.html
Aug 17 2010
next sibling parent Michal Minich <michal.minich gmail.com> writes:
On Tue, 17 Aug 2010 22:01:06 +0000, Michal Minich wrote:

 Do you care to give me the correct switches?
 
 Thanks

this example does not shows console. Maybe you can simplify it. http://digitalmars.com/d/2.0/windows.html

It was mentioned on NG that you don't need anymore WinMain and initialize runtime manually - that only 'main' is sufficient, but I did not tested it.
Aug 17 2010
prev sibling next sibling parent reply Michael Parrott <baseball.mjp gmail.com> writes:
Michal Minich Wrote:

 On Tue, 17 Aug 2010 21:40:02 +0000, John Connors wrote:
 
 Hi.
 
 This is my entire program:
 
 import std.process: system;
 
 int main(string[] argv)
 {
 	return system(r"bin\someprogram.exe");
 }
 
 It works but a console (from my program) apears while someprogram.exe is
 running. I've read that some optlink switches are needed to make the
 console disapear. Tried the following (which I found in DM FAQ), but
 don't seem to work:
 
 dmd -L/exet:nt/su:windows loader.d resource.res
 
 The console keeps appearing.
 
 Do you care to give me the correct switches?
 
 Thanks

this example does not shows console. Maybe you can simplify it. http://digitalmars.com/d/2.0/windows.html in step 3 you need to crate mydef.def file and give it as an argument to compiler. you will probably not need, but complete docs are here http://www.digitalmars.com/ctg/ctgDefFiles.html http://www.digitalmars.com/ctg/win32programming.html

If you look on that page, you'll see: 3. A .def (Module Definition File) with at least the following two lines in it: EXETYPE NT SUBSYSTEM WINDOWS Without those, Win32 will open a text console window whenever the application is run. So I'm assuming that is the answer.
Aug 17 2010
parent reply John Connors <JohnConnors mailinator.com> writes:
My small loader is not so small anymore. I've modified it according to the
sample
but the console is still showing:

import core.runtime;
import std.c.windows.windows;
import std.process: system;

extern (Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int
nCmdShow)
{
	int result;

	void exceptionHandler(Throwable e)
	{
		throw e;
	}

	try
	{
		Runtime.initialize(&exceptionHandler);
		result = system(r"bin\someprogram.exe");
		Runtime.terminate(&exceptionHandler);
	}
	catch (Object o)		// catch any uncaught exceptions
	{
		MessageBoxA(null, cast(char*)o.toString(), "Error", MB_OK |
MB_ICONEXCLAMATION);
		result = 0;		// failed
	}
	return result;
}

NOTE: The sample on the website doesn't compile because exceptionHandler()
should
receive a Throwable not an Exception.

I then added a loader.def file that looks like this:

EXETYPE NT
SUBSYSTEM WINDOWS

And to compile I'm using this line:

dmd loader.d loader.def resource.res

The console is still showing. Any ideas why?

Thanks
Aug 17 2010
parent John Connors <JohnConnors mailinator.com> writes:
That worked. Thanks.

Still wonder why execvp with a simple main() (someprogram.exe is not executed).
But for now the WinMain() version will do.

Thanks again.
Aug 17 2010
prev sibling parent Michal Minich <michal.minich gmail.com> writes:
On Tue, 17 Aug 2010 22:27:19 +0000, John Connors wrote:

 The console is still showing. Any ideas why?

try std.process.execvp
Aug 17 2010
prev sibling next sibling parent "Yao G." <nospamyao gmail.com> writes:
On Tue, 17 Aug 2010 16:40:02 -0500, John Connors  
<JohnConnors mailinator.com> wrote:

 [snip]
 It works but a console (from my program) apears while someprogram.exe is
 running. I've read that some optlink switches are needed to make the  
 console disapear.

Try using WinMain instead of main: --- import core.runtime; import std.c.windows.windows, std.process; extern(Windows) int WinMain( HINSTANCE, HINSTANCE, LPSTR, int ) { return system( r"bin\someprogram.exe" ); } --- -- Yao G.
Aug 17 2010
prev sibling next sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 17 Aug 2010 17:40:02 -0400, John Connors  
<JohnConnors mailinator.com> wrote:

 Hi.

 This is my entire program:

 import std.process: system;

 int main(string[] argv)
 {
 	return system(r"bin\someprogram.exe");
 }

 It works but a console (from my program) apears while someprogram.exe is
 running. I've read that some optlink switches are needed to make the  
 console
 disapear. Tried the following (which I found in DM FAQ), but don't seem  
 to work:

 dmd -L/exet:nt/su:windows loader.d resource.res

 The console keeps appearing.

 Do you care to give me the correct switches?

The console is appearing because of the way you are starting the child process. I don't think the linker flags passed to the loader have any bearing on what happens when you execute a child process. Changes are afoot to std.process, we recently got a blocker fixed (not yet in svn, but someone submitted a correct patch) so I can finish my Windows version. This will include a 'gui' flag that allows you to suppress the console. I don't know if the gui flag will be available on the 'system' function, but you should be able to easily run a program with the new std.process functions. -Steve
Aug 17 2010
parent "Nick Sabalausky" <a a.a> writes:
"Steven Schveighoffer" <schveiguy yahoo.com> wrote in message 
news:op.vhl46mdneav7ka localhost.localdomain...
 Changes are afoot to std.process, we recently got a blocker fixed (not yet 
 in svn, but someone submitted a correct patch)

Issue #?
Aug 18 2010
prev sibling parent "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> writes:
On Wed, 18 Aug 2010 13:50:34 -0400, Nick Sabalausky wrote:

 "Steven Schveighoffer" <schveiguy yahoo.com> wrote in message
 news:op.vhl46mdneav7ka localhost.localdomain...
 Changes are afoot to std.process, we recently got a blocker fixed (not
 yet in svn, but someone submitted a correct patch)


3979
Aug 18 2010