Page 1 of 1

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", "")