Using ProgramParameter

Mac OSX specific forum
funk.munich
User
User
Posts: 11
Joined: Wed Apr 26, 2006 9:27 pm

Using ProgramParameter

Post 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
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Using ProgramParameter

Post 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
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Re: Using ProgramParameter

Post 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
Athlon64 3700+, 1024MB Ram, Radeon X1600
funk.munich
User
User
Posts: 11
Joined: Wed Apr 26, 2006 9:27 pm

Re: Using ProgramParameter

Post 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
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Using ProgramParameter

Post 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
funk.munich
User
User
Posts: 11
Joined: Wed Apr 26, 2006 9:27 pm

Re: Using ProgramParameter

Post 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
User avatar
J. Baker
Addict
Addict
Posts: 2181
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Using ProgramParameter

Post 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", "")
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
Post Reply