xsharp.eu • Illegal char?
Page 1 of 1

Illegal char?

Posted: Mon Apr 15, 2019 10:00 am
by FFF
Folks,
FUNCTION Start( ) AS VOID
LOCAL x AS STRING
? x:= System.Environment.CommandLine
LOCAL Path AS STRING
? Path := System.IO.Path.GetDirectoryName( x)
RETURN
Compiled as a X#-Runtime app, targetting X86 to enable debugging (crashs at runtime equally with "anycpu").

Running, crashes with "illegal charakter in path "C:DevXIDEProjects4BinDebugXSharpRuntimeApp1.exe"
in the GetDirectory call.
Debugging, after setting a breakpoint at the ?Path line, shows that "x" is a empty string with length 1 (!)

Anyone an idea?
Karl

Illegal char?

Posted: Mon Apr 15, 2019 10:51 am
by TerryB1
A total and utter guess - could a space have found it's way into x ?

Terry

Illegal char?

Posted: Mon Apr 15, 2019 11:28 am
by Chris
Hi Karl,

It's because that System.Environment.CommandLine returns the command line used to execute the app, and in this case it is XIDE executing it and it always surrounds the executable with double quotes ("), in order to avoid problems with spaces. You may want to remove any such chars, before passing it to a File/Path method, or maybe you could use System.Environment.CurrentDirectory instead?

Illegal char?

Posted: Mon Apr 15, 2019 1:15 pm
by FFF
Chris,
problem with Current is, that i can't be sure this to be what i "think" it is ;)

Anyway, i already had tried a variant with
x := StrTrans(x, '"', ''), which didn't help - same error.

Initially i had touched some code, about 3 years old <g>:
FullName := System.Environment.CommandLine:Substring(1, System.Environment.CommandLine:IndexOf('"', 1) - 1)
which doesn't want to work anymore ("Out of range, Length can't be less than zero") - this did work all this time, until maybe a month ago it stopped. It's no important functionality, so i didn't bother then, but today i got in the mood...

EDIT: "Now", some hours later than my first report, nothing done with the app, i added the StrTran-Line another time - and now the crash is gone....
Returned to my main app, with the FullName code,
Seems, i'm going mad here, sorry..

Another half an hour later: the initial culprit, why my app's func didn't work anymore is found: the guy, who wrote FreeFileSync apparently changed the commandline params his tool expects.
Grrrrr....

Karl

Illegal char?

Posted: Wed Apr 17, 2019 1:12 pm
by TerryB1
Karl

If I've understood things correctly trimming x before submitting to GetDirectoryName(x) maybe worth a try.

Terry