Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-12

Problem with TProcessUTF8 and filenames with spaces

8 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

zeljko

Hi,

TCustomApplication, fpc-2.6.0

./mycmdtool --inputfile=myfile withspace.txt
GetOptionValue('i','inputfile') returns only "myfile" same thing happens if I try:
./mycmdtool "--inputfile=myfile withspace.txt"
./mycmdtool --inputfile="myfile withspace.txt"
./mycmdtool --inputfile='myfile withspace.txt'

How to fix this (have param value with space) ? Any workarounds if it's bug in TCustomApplication or whatever ?

This is tested on linux, but I need it on windows too.

zeljko

Reply by email

Michael Van Canneyt
to zeljko
zeljko wrote 6 lines
Hi, TCustomApplication, fpc-2.6.0 ./mycmdtool --inputfile=myfile withspace.txt GetOptionValue('i','inputfile') returns only "myfile"

That is normal.

same thing happens if I try: ./mycmdtool "--inputfile=myfile withspace.txt" ./mycmdtool --inputfile="myfile withspace.txt" ./mycmdtool --inputfile='myfile withspace.txt'

This is not normal.

How to fix this (have param value with space) ? Any workarounds if it's bug in TCustomApplication or whatever ?

I created the following TCustomApplication program:

procedure TMyApplication.DoRun;
var
   ErrorMsg: String;
begin
   writeln(getoptionvalue('f','file'));
   Terminate;
end;

When run it prints the correct output:

araminta: >./tc --file='my file is here.txt'
my file is here.txt
araminta: >./tc '--file=my file is here.txt'
my file is here.txt
araminta: >./tc "--file=my file is here.txt"
my file is here.txt

So I doubt the problem is there. What gets printed if you do a

For I:=0 to ParamCount do
   Writeln(Paramstr(i));

Just to rule out TCustomApplication.

You mention TProcessUTF8, that is a complicating factor. You then need to see (using strace) what the calling app actually sends. I suspect the problem is there.

Are you using the new 'parameters' or still the old 'CommandLine' ? If the latter, then it is a safe bet that the problem is there.

Michael.

Reply by email

zeljko
to Michael Van Canneyt
Michael Van Canneyt wrote 52 lines
On Sat, 8 Dec 2012, zeljko wrote: > Hi, > > TCustomApplication, fpc-2.6.0 > > ./mycmdtool --inputfile=myfile withspace.txt > GetOptionValue('i','inputfile') returns only "myfile" That is normal. > same thing happens if I try: > ./mycmdtool "--inputfile=myfile withspace.txt" > ./mycmdtool --inputfile="myfile withspace.txt" > ./mycmdtool --inputfile='myfile withspace.txt' This is not normal. > How to fix this (have param value with space) ? Any workarounds if it's > bug in TCustomApplication or whatever ? I created the following TCustomApplication program: procedure TMyApplication.DoRun; var ErrorMsg: String; begin writeln(getoptionvalue('f','file')); Terminate; end; When run it prints the correct output: araminta: >./tc --file='my file is here.txt' my file is here.txt araminta: >./tc '--file=my file is here.txt' my file is here.txt araminta: >./tc "--file=my file is here.txt" my file is here.txt So I doubt the problem is there. What gets printed if you do a For I:=0 to ParamCount do Writeln(Paramstr(i)); Just to rule out TCustomApplication. You mention TProcessUTF8, that is a complicating factor. You then need to see (using strace) what the calling app actually sends. I suspect the problem is there. Are you using the new 'parameters' or still the old 'CommandLine' ? If the latter, then it is a safe bet that the problem is there.

I'm using what TCustomApplication offers: HasOption and GetOptionValue. TProcessUTF8 isn't guilty here definitelly since I'm calling my utility from application with it, but my utility in console returns bad results, so something with TCustomApplication could be. Besides that I'm not using only one param, it's combination of short and long params. Only problem is param with spaces.

zeljko

Reply by email

Michael Van Canneyt
to zeljko
zeljko wrote 11 lines
> You mention TProcessUTF8, that is a complicating factor. > You then need to see (using strace) what the calling app actually sends. > I suspect the problem is there. > > Are you using the new 'parameters' or still the old 'CommandLine' ? > If the latter, then it is a safe bet that the problem is there. I'm using what TCustomApplication offers: HasOption and GetOptionValue. TProcessUTF8 isn't guilty here definitelly since I'm calling my utility from application with it, but my utility in console returns bad results, so something with TCustomApplication could be.

I called my app from the console and all worked fine.

TCustomApplication has no special treatment of spaces, it doesn't need that. It just uses what it gets from the OS.

Besides that I'm not using only one param, it's combination of short and long params. Only problem is param with spaces.

Well, according to my tests, TCustomApplication works fine as you can see from the output I posted. I use TCustomApplication, and often have spaces in the arguments. Never had a problem, so I do not believe the issue is there.

Please post the output (by the tool) of

For I:=0 to ParamCount do
   Writeln(Paramstr(i));

This will shed some light on the issue.

Michael.

Reply by email

zeljko
to Michael Van Canneyt
Michael Van Canneyt wrote 33 lines
On Sat, 8 Dec 2012, zeljko wrote: >> You mention TProcessUTF8, that is a complicating factor. >> You then need to see (using strace) what the calling app actually sends. >> I suspect the problem is there. >> >> Are you using the new 'parameters' or still the old 'CommandLine' ? >> If the latter, then it is a safe bet that the problem is there. > > I'm using what TCustomApplication offers: HasOption and GetOptionValue. > TProcessUTF8 isn't guilty here definitelly since I'm calling my utility > from application with it, but my utility in console returns bad results, > so something with TCustomApplication could be. I called my app from the console and all worked fine. TCustomApplication has no special treatment of spaces, it doesn't need that. It just uses what it gets from the OS. > Besides that I'm not using only > one param, it's combination of short and long params. Only problem is > param with spaces. Well, according to my tests, TCustomApplication works fine as you can see from the output I posted. I use TCustomApplication, and often have spaces in the arguments. Never had a problem, so I do not believe the issue is there. Please post the output (by the tool) of For I:=0 to ParamCount do Writeln(Paramstr(i)); This will shed some light on the issue.

ahhhhhhh :) now I see. It works when I call my utility from console, but I've called my utility via script which have same name (but it's in $HOME/bin directory), so when such params are passed to script it calls /path_to_my_utility/myutility $@
So shell kills quotes and passes garbage to the utility.

zeljko

Reply by email

Michael Van Canneyt
to zeljko
zeljko wrote 40 lines
On Saturday 08 of December 2012 17:07:57 Michael Van Canneyt wrote: > On Sat, 8 Dec 2012, zeljko wrote: >>> You mention TProcessUTF8, that is a complicating factor. >>> You then need to see (using strace) what the calling app actually sends. >>> I suspect the problem is there. >>> >>> Are you using the new 'parameters' or still the old 'CommandLine' ? >>> If the latter, then it is a safe bet that the problem is there. >> >> I'm using what TCustomApplication offers: HasOption and GetOptionValue. >> TProcessUTF8 isn't guilty here definitelly since I'm calling my utility >> from application with it, but my utility in console returns bad results, >> so something with TCustomApplication could be. > > I called my app from the console and all worked fine. > > TCustomApplication has no special treatment of spaces, it doesn't need > that. It just uses what it gets from the OS. > >> Besides that I'm not using only >> one param, it's combination of short and long params. Only problem is >> param with spaces. > > Well, according to my tests, TCustomApplication works fine as you can see > from the output I posted. I use TCustomApplication, and often have spaces > in the arguments. Never had a problem, so I do not believe the issue is > there. > > Please post the output (by the tool) of > > For I:=0 to ParamCount do > Writeln(Paramstr(i)); > > This will shed some light on the issue. ahhhhhhh :) now I see. It works when I call my utility from console, but I've called my utility via script which have same name (but it's in $HOME/bin directory), so when such params are passed to script it calls /path_to_my_utility/myutility $@ So shell kills quotes and passes garbage to the utility.

You can use $* normally ?

Michael.

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt: That is normal. This is not normal. I created the following TCustomApplication program:…
Michael Van Canneyt wrote 5 lines
var ErrorMsg: String; begin writeln(getoptionvalue('f','file')); Terminate;

Using the above as a test app, I get exactly the same results and Michael. It works fire here under Linux (OpenSUSE 12.2)

----8<-------------8<-------------8<-------------8<-------------8<---- [tmp]$ ./project1

[tmp]$ ./project1 -f "my long file.txt"
my long file.txt
[tmp]$ ./project1 -f 'my long file.txt'
my long file.txt
[tmp]$ ./project1 --file="my long file.txt"
my long file.txt
[tmp]$ ./project1 "--file=my long file.txt"
my long file.txt
[tmp]$ ./project1 --file='my long file.txt'
my long file.txt
----8<-------------8<-------------8<-------------8<-------------8<----

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

zeljko
to Graeme Geldenhuys
Graeme Geldenhuys wrote 27 lines
On 2012-12-08 11:30, Michael Van Canneyt wrote: > var > > ErrorMsg: String; > > begin > > writeln(getoptionvalue('f','file')); > Terminate; Using the above as a test app, I get exactly the same results and Michael. It works fire here under Linux (OpenSUSE 12.2) ----8<-------------8<-------------8<-------------8<-------------8<---- [tmp]$ ./project1 [tmp]$ ./project1 -f "my long file.txt" my long file.txt [tmp]$ ./project1 -f 'my long file.txt' my long file.txt [tmp]$ ./project1 --file="my long file.txt" my long file.txt [tmp]$ ./project1 "--file=my long file.txt" my long file.txt [tmp]$ ./project1 --file='my long file.txt' my long file.txt ----8<-------------8<-------------8<-------------8<-------------8<----

Yes, everything is ok, I've used script instead of cmd program directly.

zeljko

Reply by email