logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
restartCmd = nwnx_restart.bat
Goto page Previous  1, 2
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Technical support
View previous topic :: View next topic  
Author Message
Grinning Fool



Joined: 12 Feb 2005
Posts: 264

PostPosted: Fri Apr 27, 2007 16:27    Post subject: Reply with quote

An good idea -- should be doable. Would you need spaces in your parameters (such as for a module name with spaces)? If so, I would have to put a limit to the number of args, since I don't have any way to embed quotes in outgoing strings.

For example:

NWNXUtil_LaunchCommand(string commandname, string arg1= "", string arg2 = "", string arg3 = "", string arg4 = "", string arg5 = "");

If spaces were not needed in arguments, the signature would look like this:
NWNXUtil_LaunchCommand(string commandname, string arguments = "");

The reason for this is that this is not legal in nwscript that I know of:
NWNXUtil_LaunchCommand("Command1", "argument1 \"argument with spaces\" argument3");

Hmm... but what I could do is allow a separate character to use between arguments, such as comma:
NWNXUtil_LaunchCommand("Command1", "argument1,argument with spaces,argument3");

Perhaps that last would be the best way to do it. Could even make the separator character configurable in the INI file.
_________________
Khalidine, a NWN2 persistent world

Looking for volunteers.
Back to top
View user's profile Send private message
redils



Joined: 13 Jan 2005
Posts: 27

PostPosted: Fri Apr 27, 2007 17:14    Post subject: Reply with quote

Many thanks.

It doesn't matter to me, in fact, i give it an integer parameter (the id of the nwnx service to start). But, you're right, the best way is to give a list of parameters split by a separator, cause this feature could be used for many other usefull things ^^

Redils
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Sat Apr 28, 2007 2:31    Post subject: Reply with quote

Grinning Fool wrote:
An good idea -- should be doable. Would you need spaces in your parameters (such as for a module name with spaces)? If so, I would have to put a limit to the number of args, since I don't have any way to embed quotes in outgoing strings.

For example:

NWNXUtil_LaunchCommand(string commandname, string arg1= "", string arg2 = "", string arg3 = "", string arg4 = "", string arg5 = "");

If spaces were not needed in arguments, the signature would look like this:
NWNXUtil_LaunchCommand(string commandname, string arguments = "");

The reason for this is that this is not legal in nwscript that I know of:
NWNXUtil_LaunchCommand("Command1", "argument1 \"argument with spaces\" argument3");

Hmm... but what I could do is allow a separate character to use between arguments, such as comma:
NWNXUtil_LaunchCommand("Command1", "argument1,argument with spaces,argument3");

Perhaps that last would be the best way to do it. Could even make the separator character configurable in the INI file.


I'm using a single string, with parameter binding eg
NWNX_Process("Command.exe ? ?");
NWNX_ProcArg("abc",true); //*1
NWNX_ProcArg("123",false); //*1
NWNX_Spawn(false); //*2

*1 The true/false indicates if the argument needs to be quoted, or not.
*2 True if you need to wait for the process to complete, False otherwise

--Very do able, and works well too.
I use this to create/update my database schema by running a SQLCMD session during Module_On_Load() . A bit problematic is the job takes more than 2-3 seconds and you are waiting. -- An ideal addition to send admin email notifications Wink

Lots of ways you could do this.
--Note to self, must turn this into a stand-alone plug-in.

Cheers
Gryphyn
Back to top
View user's profile Send private message
Grinning Fool



Joined: 12 Feb 2005
Posts: 264

PostPosted: Sun Apr 29, 2007 4:11    Post subject: Reply with quote

Gryphyn wrote:
Grinning Fool wrote:
An good idea -- should be doable. Would you need spaces in your parameters (such as for a module name with spaces)? If so, I would have to put a limit to the number of args, since I don't have any way to embed quotes in outgoing strings.

For example:

NWNXUtil_LaunchCommand(string commandname, string arg1= "", string arg2 = "", string arg3 = "", string arg4 = "", string arg5 = "");

If spaces were not needed in arguments, the signature would look like this:
NWNXUtil_LaunchCommand(string commandname, string arguments = "");

The reason for this is that this is not legal in nwscript that I know of:
NWNXUtil_LaunchCommand("Command1", "argument1 \"argument with spaces\" argument3");

Hmm... but what I could do is allow a separate character to use between arguments, such as comma:
NWNXUtil_LaunchCommand("Command1", "argument1,argument with spaces,argument3");

Perhaps that last would be the best way to do it. Could even make the separator character configurable in the INI file.


I'm using a single string, with parameter binding eg
NWNX_Process("Command.exe ? ?");
NWNX_ProcArg("abc",true); //*1
NWNX_ProcArg("123",false); //*1
NWNX_Spawn(false); //*2

*1 The true/false indicates if the argument needs to be quoted, or not.
*2 True if you need to wait for the process to complete, False otherwise

--Very do able, and works well too.
I use this to create/update my database schema by running a SQLCMD session during Module_On_Load() . A bit problematic is the job takes more than 2-3 seconds and you are waiting. -- An ideal addition to send admin email notifications Wink

Lots of ways you could do this.
--Note to self, must turn this into a stand-alone plug-in.

Cheers
Gryphyn


I had given that some thought initially, but ultimately figured to go with ease of use provided by just a single invocation.
_________________
Khalidine, a NWN2 persistent world

Looking for volunteers.
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Sun Apr 29, 2007 9:29    Post subject: Reply with quote

I've extracted the code and it's in it's own plug-in now. (and simplified it a bit)

@GF, with both a single command option and an argument based one.

BUT, I've hit a weird issue.
Every "\" character is being stripped from
char* parameters
Is this just my build? It's happening before it gets to my plug-in.

So a request like "cmd /K dir\w" ends up as "cmd /K dirw" and fails.
mind you "cmd /K dir" works fine.

This means that I have a plug-in that can execute any process in the plug-ins folder (where you don't enter a path - at least for windows)

nwnxProcExecute("cmd /K dir");

nwnxProcCommand("cmd /K ?");
nwnxProcArgument("c:\Program Files\*.*"); //Currently not working???
nwnxProcSpawn("NOWAIT");

Code:

Trace: (TRACE_VERBOSE) * Plugin DoRequest(0x12fc50, COMMAND, cmd /K dir)
Trace: (TRACE_VERBOSE) * function=COMMAND
Trace: (TRACE_VERBOSE) * Command = cmd /K dir
Trace: (TRACE_VERBOSE) * Plugin DoRequest(0x12fc50, SPAWN, NOWAIT)
Trace: (TRACE_VERBOSE) * function=SPAWN
Trace: (TRACE_VERBOSE) * Spawning Process = cmd /K dir
Trace: (TRACE_VERBOSE) * Plugin DoRequest(0x12fc50, COMMAND, cmd /K ?)
Trace: (TRACE_VERBOSE) * function=COMMAND
Trace: (TRACE_VERBOSE) * Command = cmd /K ?
Trace: (TRACE_VERBOSE) * Plugin DoRequest(0x12fc50, ARGUMENT, c:Program Files*.*)
Trace: (TRACE_VERBOSE) * function=ARGUMENT
Trace: (TRACE_VERBOSE) * Argument(0) = c:Program Files*.*
Trace: (TRACE_VERBOSE) * Plugin DoRequest(0x12fc50, SPAWN, NOWAIT)
Trace: (TRACE_VERBOSE) * function=SPAWN
Trace: (TRACE_VERBOSE) * Spawning Process = cmd /K "c:Program Files*.*"


I'll publish if I can sort out the "\" removal issue.

Cheers
Gryphyn
Back to top
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Sun Apr 29, 2007 10:50    Post subject: Reply with quote

'\' is used for escaping characters in C (e.g. \n meaning new line). You could write

c:\\program files\\Directory

in order to avoid that. But that's just a workaround. I guess there should be a function somewhere in the Win32 (or better: wxWidgets) API that takes care of that problem, maybe by converting every \ to \\.
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Sun Apr 29, 2007 14:11    Post subject: Reply with quote

Papillon wrote:
'\' is used for escaping characters in C (e.g. \n meaning new line). You could write

c:\\program files\\Directory

in order to avoid that. But that's just a workaround. I guess there should be a function somewhere in the Win32 (or better: wxWidgets) API that takes care of that problem, maybe by converting every \ to \\.


Yes, I know this... but this 'stripping' is happening in the 'payload' somewhere. "c:\Program Files\*.*" is the content of the NWN2 string - the char* being passed. But within the OnRequest function the "\" characters have already been removed.
char* points to memory of 'c',':','P','r'...etc. no '\'s

And it's every "\", I tried a double-up in the NWN2 string and ended with the same result. - no "\"s present. I don't get the opportunity escape the escapes as it were.

I'm using multi-byte, but that shouldn't be the issue.

NWScript: nwnxProcArgument("c:\Program Files\*.*");
Trace: (TRACE_VERBOSE) * Plugin DoRequest(0x12fc50, ARGUMENT, c:Program Files*.*)

Cheers
Gryphyn
Back to top
View user's profile Send private message
Grinning Fool



Joined: 12 Feb 2005
Posts: 264

PostPosted: Sun Apr 29, 2007 20:02    Post subject: Reply with quote

Maybe try and see what happens if you just add:
PrintString("Test of \ and \\");

I'm suspecting that it may be occurring as far back as the nwn compiler level.
_________________
Khalidine, a NWN2 persistent world

Looking for volunteers.
Back to top
View user's profile Send private message
nosfe



Joined: 25 Apr 2007
Posts: 22

PostPosted: Tue May 01, 2007 21:38    Post subject: Reply with quote

mhh ok, im very happy to considere my request ^^

now this problem with the "\" , I had'nt thought of it, I leave it to you to make as well as possible

I had just thought that the only place to put a way exemple: “c:\program files\softbackup\cobianbackup.exe” “param1”, “param2”… but not in the parameters.

or this "cmd copy", "folder\nameplayer.bic folderOnOtherServeurMod\"
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Tue May 01, 2007 23:34    Post subject: Reply with quote

The problem with "\" is that any work-around will have to be done in NWScript. Most likely you will need to enter "/" as the path separator, and a flag to indicate that it needs to be flipped (for windows).
Maybe the NWNX_? script functions pass a raw byte-stream - and this problem will go away.

Cheers
Gryphyn
Back to top
View user's profile Send private message
nosfe



Joined: 25 Apr 2007
Posts: 22

PostPosted: Tue Jun 26, 2007 8:24    Post subject: Reply with quote

where be you relating to this request please ? Laughing
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Tue Jun 26, 2007 15:50    Post subject: Reply with quote

Still stumped with the "\" weirdness...

I'm now 'Escaping' the (pipe) "|" character and converting it to a "\".

This gets returned to NWN2.
From then on it actually passes back the "\" character.

Should have something for the weekend.

Cheers
Gryphyn
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Wed Jun 27, 2007 11:41    Post subject: Reply with quote

Check it here...

Spawn Plugin v106.108.1.1
Requires NWNX4 v1.08

The Spawn Plugin gives your server access to many command options.

You can run a Program, execute a command or even look at your environment settings.

SpawnEnvironment(string sEnvVariable)
SpawnProgram(string sProgramName)
SpawnCommand(string sCommand)

but to do this there are some 'tricks' that you need to master...

SpawnEscape(string sString)
- changes the '|' character to a '\' character so you can enter PATH strings
- eg SpawnEscape("c:|temp") = "c:\temp"
SpawnQuote(string sString)
- provides double quotes around a string (with double-ups)
- eg SpawnQuote("string") = "string" (literally, with quote characters)

It will take some time to master, especially getting the quotes right, but once you have it...

Cheers
Gryphyn
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Technical support All times are GMT + 2 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group