RunProgram parameter quotation problem

Linux specific forum
Marlin
Enthusiast
Enthusiast
Posts: 406
Joined: Sun Sep 17, 2006 1:24 pm
Location: Germany

RunProgram parameter quotation problem

Post by Marlin »

I'm trying to run wget from purebasic.

Code: Select all

Global lngProgram.l
Global strErrLine.s
Global strEBuffer.s

lngProgram = RunProgram("wget", "--load-cookies=" + Chr(34) + "/home/martin/Cookie Folder/cookies.txt" + Chr(34) + " " + Chr(34) + "http://www.google.com" + Chr(34), "", #PB_Program_Error | #PB_Program_Open)

While ProgramRunning(lngProgram)
  Repeat
    strErrLine = ReadProgramError(lngProgram)
    If strErrLine
      strEBuffer + #CRLF$ + strErrLine
    EndIf
  Until strErrLine = ""
  Delay(20)
Wend
Repeat
  strErrLine = ReadProgramError(lngProgram)
  If strErrLine
    strEBuffer + #CRLF$ + strErrLine
  EndIf
Until strErrLine = ""

Debug ProgramExitCode(lngProgram)

CloseProgram(lngProgram)

Debug strEBuffer
However something seems wrong with the quotations.

I get the following debug output:

Code: Select all

0

Cannot open cookies file `"/home/martin/Cookie': No such file or directory
--14:49:53--  http://folder/cookies.txt%22
           => `cookies.txt"'
Resolving folder... failed: Name or service not known.
--14:49:53--  http://www.google.com/
           => `index.html.1'
Resolving www.google.com... 209.85.129.104, 209.85.129.147, 209.85.129.99
Connecting to www.google.com|209.85.129.104|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://www.google.de/ [following]
--14:49:53--  http://www.google.de/
           => `index.html.1'
Resolving www.google.de... 209.85.129.104, 209.85.129.99, 209.85.129.147
Reusing existing connection to www.google.com:80.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
    0K .....                                                    60.25 KB/s
Obviously it's trying to use
"/home/martin/Cookie
as cooky path.

Removing the space from the path does not help,
as it is also treating the quotation mark as part of the path.

It only works with a path with no spaces and leaving out the quotation marks.

Stangely it seems to have not problems with the quotation marks around the url!

I tried escapeing spaces or quotation marks with backslashes, but that does not help.

I can run the same string from bash and it works without a problem.
I'm using GNU Wget 1.10.2.

Can anyone help me to find out what's wrong or how to get that to work?
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

try this:

Code: Select all

lngProgram = RunProgram("wget", Chr(34) + "--load-cookies=/home/martin/Cookie Folder/cookies.txt" + Chr(34) + " " + Chr(34) + "http://www.google.com" + Chr(34), "", #PB_Program_Error | #PB_Program_Open) 
quidquid Latine dictum sit altum videtur
Marlin
Enthusiast
Enthusiast
Posts: 406
Joined: Sun Sep 17, 2006 1:24 pm
Location: Germany

Post by Marlin »

Excellent :D

And the same principle also works for the user-agent parameter.


However my understanding about, why this works is rather dim.
(The other method of quoting worked with bash and also with W2K.)

Could you add a few words of explanation?
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

On Windows, the parameters are parsed by the system. On Linux the RunProgram() command itself does the parsing and passes the argv array when executing the new program.
The PB parsing only looks for quotation marks at the beginning and end of the parameters so far. I could add that for the future though.
quidquid Latine dictum sit altum videtur
Marlin
Enthusiast
Enthusiast
Posts: 406
Joined: Sun Sep 17, 2006 1:24 pm
Location: Germany

Post by Marlin »

It is helpfull to know about that.

Thank you.
Post Reply