Page 1 of 1

Using ProgramParameter

Posted: Sat Dec 03, 2011 3:44 pm
by funk.munich
Hi everybody,

do someone know how I can use ProgramParameter under Mac OS (10.7.2).
What I did:

(1) Create stupid program

Code: Select all

For i = 0 To CountProgramParameters()
  PrintN(ProgramParameter(i))  
Next
(2) Compile Options
- Executable Format = Console

(3) PureBasic has created a "test.app"

Code: Select all

drwx------   3 daniel  staff    102  3 Dez 15:19 test.app
(4) When I run the app with commands I retrieve only the following:

Code: Select all

test hello world
-bash: test: hello: unary operator expected
Any suggestions from your side?

Many thanks in advance,
Daniel

Re: Using ProgramParameter

Posted: Sat Dec 03, 2011 8:50 pm
by IdeasVacuum
unary operator expected
That seems to be your clue - some sort of prefix or other syntax required, such as /h/e/l/l/o /w/o/r/l/d

Re: Using ProgramParameter

Posted: Sat Dec 03, 2011 10:42 pm
by remi_meier
'test' is a built-in bash 'program' :mrgreen:
See here: http://ss64.com/bash/test.html

If it's anything like on Linux, you'll have to refer to your application as

Code: Select all

./test.app
And I think you start an "application bundle" with

Code: Select all

open ./test.app first_arg

Re: Using ProgramParameter

Posted: Sun Dec 04, 2011 11:49 am
by funk.munich
Hi everybody,

thanks for your help however both suggestion from you does not help :-(
Did it work on your system (Mac OS)?

Thx,
Daniel

Re: Using ProgramParameter

Posted: Sun Dec 04, 2011 1:18 pm
by Shardik
Please try my following working code example. If you want to test
the example from the IDE you need to use OpenConsole(). Otherwise
you can delete it.

In order to start my example in a console you have to change the
"Executable format" in "Compiler/Compiler Options..." from "MacOS"
to "Console" before compiling and saving the example.

Before starting the compiled example you have to start a console
("Terminal"), change into the folder with your compiled "test" program
and start it with
./test hello world
An alternative way is to type in the complete path to "test":
(This is the correct path on my Mac, of course you have to change it
to the correct path on your Mac. Please note that I had to use double
quotes because the path contains a blank in the subfolder "MacOS X".)
"/Volumes/DATEN/Programmierung/PureBASIC/Beispiele/MacOS X/Downloads/Konsole/test1" hello world

Code: Select all

If OpenConsole()
  If CountProgramParameters() = 0
    PrintN("No program parameters detected!")
  Else
    For i = 0 To CountProgramParameters() - 1
      PrintN(ProgramParameter(i)) 
    Next
  EndIf

  PrintN("")
  PrintN("Press <Enter> to continue...")
  Input()
EndIf

Re: Using ProgramParameter

Posted: Tue Dec 06, 2011 10:11 am
by funk.munich
Hi Shardik,

many thanks ... you're right ... in this way it works as expected.
I tried to combine GUI with Console and add the wrong information into the code.

Thx for your help,
Daniel

Re: Using ProgramParameter

Posted: Wed Mar 13, 2013 3:03 am
by J. Baker
Here's an example of ProgramParameter() using a normal window.

Compile the following as "Test.app" to your desktop.

Code: Select all

If OpenWindow(0, 0, 0, 400, 260, "Receive Parameters", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
  
   EditorGadget(0, 5, 5, 390, 250)
   
   For i = 0 To CountProgramParameters() - 1
    AddGadgetItem(0, i, ProgramParameter(i))
   Next
   
 Repeat
    
  Event = WaitWindowEvent()

 Until Event = #PB_Event_CloseWindow
  
EndIf

End
Then run the following code.

Code: Select all

RunProgram("open", GetHomeDirectory() + "Desktop/Test.app --args Hello World", "")