Support #269

Running a Wt application without using command arguments

Added by Anonymous about 2 years ago. Updated 10 months ago.

Status:Closed Start:01/16/2010
Priority:Normal Due date:
Assigned to:Koen Deforche % Done:

0%

Category:-
Target version:-

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.

History

Updated by Koen Deforche about 2 years ago

  • Status changed from New to Feedback
  • Assigned to 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 Koen Deforche 10 months ago

  • Status changed from Feedback to Closed

I guess it was ?

Updated by Richel Bilderbeek 10 months 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

Also available in: Atom PDF