Page 1 of 1
Running executables with spaces on xboard
Posted:
10 Aug 2008, 20:28
by Pradu
I'm trying to get PSWBTM to work with xboard but I ran into a problem. I don't know how to run executables with spaces for xboard. For Winboard, something like this would work:
- Code: Select all
xboard -fd "/home/pradu/Desktop/Buzz" -fcp '"./Buz 2" -log'
But this doesn't work for xboard. Is there any way to launch executables with spaces for xboard?
Re: Running executables with spaces on xboard
Posted:
10 Aug 2008, 21:30
by H.G.Muller
When you call xboard, you probably use exec() to call it. Arguments in exec() are passed in a structured way, as an array of strings. So it would be obvious to xboard that "./Buzz 2" is a single argument, because it is in a single string.
I don't think that you need to do the actual quoting. That is shell input syntax in Linux, to indicate that the string within the quote is a single argument. But the shell takes that information, strips the quotes off, and passes the stuff within quotes as a single argument to exec.
This might be the problem: that you pass quoted arguments, and that xboard chokes on them,
Re: Running executables with spaces on xboard
Posted:
10 Aug 2008, 21:45
by H.G.Muller
Sorry, I see now your question is more subtle than that. You have quotes within quotes.
I looked at the xboard code, and the answer is: NOT POSSIBLE. The code in xboard to startup the engine child is very simpleminded: it takes the string passed as -fcp, scans it for spaces, and cuts it at every space into a separate argument. It does not scan for quotes or escapes or anything.
Is this a problem? It is still not too late to try to make it slightly more smart. E.g. delete single quotes, and not cut at speces in between those. But I's rather not., as I cannot test it, and it seems bug-prone. So I'd rather live with the fact that spaces in file names are not allowed. I thought that Linux people would be smart enough to not use such filenames...
Re: Running executables with spaces on xboard
Posted:
10 Aug 2008, 22:07
by H.G.Muller
OK, if you can compile xboard yourself, you can try to make the following modification in the routine StartChildProcess() in xboard.c:
- Code: Select all
for (;;) {
#if 1
while(*p == ' ') p++; // skip leading spaces
if(*p == '"') {
argv[i++] = ++p;
p = strchr(p, '"');
} else if(*p == '\'') {
argv[i++] = ++p;
p = strchr(p, '\'');
} else {
argv[i++] = p;
p = strchr(p, ' ');
}
#else
argv[i++] = p;
p = strchr(p, ' ');
#endif
if (p == NULL) break;
*p++ = NULLCHAR;
}
This would treat single and double quoting in the engine command line, and let it protect anything. If you make it #if 0, you have the original code.
Re: Running executables with spaces on xboard
Posted:
11 Aug 2008, 00:27
by Zach Wegner
I patched this too on SVN.