Illegal char?

This forum is meant for questions and discussions about the X# language and tools
Post Reply
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Illegal char?

Post 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
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
TerryB1
Posts: 306
Joined: Wed Jan 03, 2018 11:58 am

Illegal char?

Post by TerryB1 »

A total and utter guess - could a space have found it's way into x ?

Terry
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Illegal char?

Post 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?
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Illegal char?

Post 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
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
TerryB1
Posts: 306
Joined: Wed Jan 03, 2018 11:58 am

Illegal char?

Post by TerryB1 »

Karl

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

Terry
Post Reply