RunProgram string passing problem

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

In the first part of my program, I am passing a SHORT directory name as a literal because it never changes and enclosing the second directory in quote marks because the path and filename have spaces in them. THis works in this part of the program.

Code: Select all

unpacker.s = curdir + "\extract.exe" ; This is C:\iCat\extract.exe
params.s = " /Y /E /L C:\iCat2\ " + Chr(34) + diskfile.s + Chr(34) + " content.ini"

If RunProgram(unpacker.s, params.s, "", 1 | 2)  0
EndIf
Later on, I do this below because both curdir.s and diskfile.s contain spaces but this isn't working for some reason.

Code: Select all

params.s = " /Y /E /L  " + Chr(34) + curdir.s + "\View  " + diskfile.s + Chr(34) + "  " + "*.*" ; Make unpack String

If RunProgram("extract.exe", params.s, "", 1 | 2)  0  : EndIf
I've even tried

Code: Select all

params.s = " /Y /E /L  " + Chr(34) + curdir.s + "\View  " + chr(34) + " " + chr(34) + diskfile.s + Chr(34) + "  " + "*.*" 
Didn't make any difference. As long as I start to introduce long string with spaces to RunProgram, it doesn't seem to matter how I present them, they don work.

When I type out entire command line in a console, complete with the literal quote marks, it works so I know it's correct. Just can't get RunProgram to pass it through properly


We are Dyslexic of Borg, prepare to have your ass laminated!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> params.s = " /Y /E /L " + Chr(34) + curdir.s + "\View " + diskfile.s + Chr(34) + " " + "*.*" ; Make unpack String

What does params.s look like? Can you post its contents here?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

Params.s can look like either of the two below, I have tried both. If I type the params exactly as they are illustrated below into a console window, it works fine perfectly. Passing them in the way that I do (shown in my earlier message) does not.
1.)

/Y /E /L "C:\Development\My Code\iCat\View" "E:\IncrediMail\a\angel teddy bears.imf" *.*

2.)

/Y /E /L "C:\Development\My Code\iCat\View E:\IncrediMail\a\angel teddy bears.imf" *.*

We are Dyslexic of Borg, prepare to have your ass laminated!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Jose.

Here is a test I did;
Add comments to test variations

; Call copy of NOTEPAD.EXE
AppPath.s = "C:\Program Files\Common Files\New Folder\New Folder\New Folder\New Folder Deep\NOTEPAD.EXE"

; Call PureBasic App instead of NOTEPAD
AppPath.s = "C:\Program Files\Common Files\New Folder\New Folder\New Folder\New Folder Deep\TESTAPP.EXE"

; The parameters we want to pass
Param.s = "C:\Program Files\Common Files\New Folder\New Folder\New Folder\New Folder Deep\Testing File.txt"

; When calling a PureBasic APP we need the quotes around the parameters string
Param.s = Chr(34)+"C:\Program Files\Common Files\New Folder\New Folder\New Folder\New Folder Deep\Testing File.txt"+Chr(34)

If RunProgram(AppPath, Param, "", 0) 0 : EndIf
END

the TestApp Code:
MessageRequester("Hello World with parameters", "Called With["+ProgramParameter()+"]", 0)
END

I found that when calling Notepad the parameter could be without CHR(34) "Double Quotes", but this is not same behaviour when calling a PB app, in this case it must contain outside Double Quotes.

Maybe this is bug in PB ProgramParameter(), the calls look ok.
Hope this helps

Registered PureBasic User
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> /Y /E /L "C:\Development\My Code\iCat\View" "E:\IncrediMail\a\angel teddy bears.imf" *.*
> /Y /E /L "C:\Development\My Code\iCat\View E:\IncrediMail\a\angel teddy bears.imf" *.*

So the above two lines are the param$ part of RunProgram?
If so, does it work if you put the quotes at the start and
end only, like this:

"/Y /E /L C:\Development\My Code\iCat\View E:\IncrediMail\a\angel teddy bears.imf *.*"

I don't know if it will, but give it a try, as I think the
param$ part has to be one complete string...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

"/Y /E /L C:\Development\My Code\iCat\View E:\IncrediMail\a\angel teddy bears.imf *.*"

Tried this and still nothing. Am totally stumped.

One thing I haven't tried is to open a console instead to see the output of the external program to see if it says anything at all and that's my next job. No other way of getting feedback from it (frustrated look)


We are Dyslexic of Borg, prepare to have your ass laminated!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Am totally stumped.

Okay, to test if it's a RunProgram bug, try your code with the API
command ShellExecute instead. Like this:

ShellExecute_(0,0,executable$,parameter$,workingpath$,0)

If this works, then RunProgram has a bug.
If not, then parameter$ is the cause of the problem.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

I actually had a thought (GASP!!)...counting up the number of characters passed exceeds 128. Ins't this acommand line limit?? (I seem to remember somewhere)


We are Dyslexic of Borg, prepare to have your ass laminated!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by waffle.

i have looked at this too, and think this is a windows bug and not a PB bug. I tested by calling a .BAT file from dos and found i still can't use path names with a space included in the name.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.
Originally posted by waffle

i have looked at this too, and think this is a windows bug and not a PB bug. I tested by calling a .BAT file from dos and found i still can't use path names with a space included in the name.
I've been able to use path names with spaces berfore as long as I enclose the path with quote marks. It is beginning to seem more and more like a problem with command line length exceeding 128 characters :(

We are Dyslexic of Borg, prepare to have your ass laminated!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

This command line works perfectly from a DOS/command line window
====================================================================
C:\Documents and Settings\Administrator>"c:\development\my code\icat\extract.exe
" /y /e /l "c:\development\my code\icat\view" "e:\incredimail\a\a big sweet kiss
for you.imf" *.d*
====================================================================
The equivalent string passer in PB is:

curdir.s = Space(512)
result = GetCurrentDirectory_(Len(curdir), @curdir)

extract.s = chr(34) + curdir.s + "\view " + chr(34)

params.s = " /y /e /l " + Chr(34) + curdir.s + "\view " + Chr(34) + " " + Chr(34) +
diskfile.s + Chr(34) + " *.*"

RunProgram(extract.s, params.s, "", 1 | 2)

We are Dyslexic of Borg, prepare to have your ass laminated!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.
Originally posted by PB

> Am totally stumped.

Okay, to test if it's a RunProgram bug, try your code with the API
command ShellExecute instead. Like this:

ShellExecute_(0,0,executable$,parameter$,workingpath$,0)

If this works, then RunProgram has a bug.
If not, then parameter$ is the cause of the problem.
Same problem. I wish I could capture the output of the program, if I saw the error message, then I could perhaps fix it. Debugging the variables just shows exactly what I was trying to do but not what happened.

We are Dyslexic of Borg, prepare to have your ass laminated!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Same problem.

:cry:

> unpacker.s = curdir + "\extract.exe" ; This is C:\iCat\extract.exe

I was just looking at this... try having unpacker.s just as "extract.exe"
alone, and "c:\icat\" for the workingpath$ parameter...?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

Yes, I finally had to do that. SHortening the strings so they would be under 128 chars fixes the problem. But hardcoding it like this is a bad solution, didn't want to do that :(

We are Dyslexic of Borg, prepare to have your ass laminated!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

This works fine here:

Code: Select all

q.s=Chr(34)
curdir.s=Space(512)
GetCurrentDirectory_(Len(curdir),@curdir)
 
unpack.s=q+curdir+"\Extract32.exe"+q
diskfile.s=curdir+"\test.imf"
params.s=" /y /e /l "+q+curdir+"\view"+q+" "+q+diskfile+q+" *.hlp" 
 
RunProgram(unpack,params,"",1|2)
Of course extra files needed:
- Extract32.exe
- test.imf (which contains a .hlp file)


----------
Visit the PB Resources Site at http://www.reelmediaproductions.com/pb
Post Reply