FileName$ AND Parameter$ in one parameter for RunProgram?
Posted: Thu Feb 22, 2007 7:30 pm
Hello!
It would be alot easier if I could just pass the FileName$ along with the Parameter$ in one parameter instead of two in RunProgram..
So something like this:
RunProgram(Command$ [, WorkingDirectory$ [, Flags [, SenderProgram]]])
Instead of this:
RunProgram(FileName$ [, Parameter$, WorkingDirectory$ [, Flags [, SenderProgram]]])
Right now I am using this (probably very bad) alternative way:
This would be extremly useful if you need to execute a command that the user inputs somewhere in your application.. For example this: http://www.purebasic.fr/english/viewtopic.php?t=25966
It would be alot easier if I could just pass the FileName$ along with the Parameter$ in one parameter instead of two in RunProgram..
So something like this:
RunProgram(Command$ [, WorkingDirectory$ [, Flags [, SenderProgram]]])
Instead of this:
RunProgram(FileName$ [, Parameter$, WorkingDirectory$ [, Flags [, SenderProgram]]])
Right now I am using this (probably very bad) alternative way:
Code: Select all
Command$="example-program parameter1 parameter2"
If Trim(FindString(Command$, " ", 0))<>0 ; If there are spaces (probably having a parameter next to them)..
CommandPos=FindString(Command$, " ", 0)-1 ; See where the first space is..
ACommand$=Trim(Left(Command$, CommandPos)) ; Cut only the FileName$ part of the Command$...
BCommand$=Trim(Mid(Command$, CommandPos+2, Len(Command$)-CommandPos)) ; Now cut the parameters from Command$..
Else ; If there are no spaces..
ACommand$=Command$ ; The future FileName$ will be Command$
BCommand$="" ; And the parameter part will be blank..
EndIf
RunProgram(ACommand$, BCommand$, "", #PB_Program_Read|#PB_Program_Open) ; Run the program.. (duh)