Using ProgramParameter

Mac OSX specific forum
User avatar
Shardik
Addict
Addict
Posts: 2067
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: 2192
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