FileName$ AND Parameter$ in one parameter for RunProgram?

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
merihevonen
Enthusiast
Enthusiast
Posts: 326
Joined: Mon Jan 01, 2007 7:20 pm

FileName$ AND Parameter$ in one parameter for RunProgram?

Post by merihevonen »

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:

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)
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
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: FileName$ AND Parameter$ in one parameter for RunProgram

Post by PB »

RunProgram is a wrapper for the ShellExecute API, so I doubt it'll change.

Anyway, this seems easier to me for what you want to accomplish:

Code: Select all

Command$="example-program parameter1 parameter2"
;Command$="example-program" ; No parameters.
sp=FindString(Command$," ",1)
ACommand$=Left(Command$,sp-1)
BCommand$=Mid(Command$,sp+1,Len(Command$))
If ACommand$="" : Swap ACommand$,BCommand$ : EndIf
Debug ACommand$
Debug BCommand$
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

You can use the WinExec API

Code: Select all

WinExec_("notepad E:\Eigene Dateien\BASIC.txt", #SW_SHOWNORMAL)
Last edited by ts-soft on Thu Feb 22, 2007 9:36 pm, edited 1 time in total.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
merihevonen
Enthusiast
Enthusiast
Posts: 326
Joined: Mon Jan 01, 2007 7:20 pm

Post by merihevonen »

ts-soft wrote:You can use the WinExec API

Code: Select all

WinExec_("notepad E:\Eigene Dateien\BASIC.txt", #SW_NORMAL)
Linux? :?

EDIT: Thanks PB for the code!
Post Reply