Support #269
closedRunning a Wt application without using command arguments
0%
Description
As the title already says a bit, I'm having trouble running a Wt application without using command arguments.
The following code is to represent the same command arguments as the example applications use (printing them shows the exact same as usual):
int argc = 5;
char argv = new char*[argc];
TCHAR path[_MAX_PATH + 1];
::GetModuleFileName(NULL, path, _MAX_PATH + 1);
argv[ 0 ] = path;
argv[ 1 ] = "---http-address=0.0.0.0";
argv[ 2 ] = "---http-port=8080";
argv[ 3 ] = "---deploy-path=/hello";
argv[ 4 ] = "---docroot=.";
WServer server(argv[ 0 ]);
server.setServerConfiguration(argc, argv, WTHTTP_CONFIGURATION);
As soon as "setServerConfiguration" is called, the application crashes.
Without any reason in my thoughts as I'm using the same variable types and values.
Thanks for your support,
Johnny
ps. Sorry for not using code tags if there's the possibility to, I didn't managed to find the feature.
Updated by Koen Deforche about 14 years ago
- Status changed from New to Feedback
- Assignee set to Koen Deforche
Hey Johnny,
I cannot reproduce this on Linux, so I wonder if the problem is with the GetModuleName() method ?
The following works for me:
int main()
{
int argc = 5;
char** argv = new char*[argc];
argv[ 0 ] = "foobar";
argv[ 1 ] = "--http-address=0.0.0.0";
argv[ 2 ] = "--http-port=8080";
argv[ 3 ] = "--deploy-path=/hello";
argv[ 4 ] = "--docroot=.";
WServer server(argv[0]);
server.setServerConfiguration(argc, argv, WTHTTP_CONFIGURATION);
server.addEntryPoint(Application, &createApplication);
server.start();
sleep(1000);
}
Updated by Richel Bilderbeek about 13 years ago
The problem with the approach above (using int main(), instead of int main(int argc, char* argv[]) is that the command-line arguments from the user are ignored.
I use Boost.Options for this, and this is described at http://richelbilderbeek.nl/CppWtAutoRun.htm
Have fun, Richel Bilderbeek