Page 1 of 1

runprogram - need help

Posted: Sun Jun 03, 2012 10:56 pm
by michel51
Hello List,

in a project I want to compile a given PB-file.
but the following code (example) don't work.

Code: Select all

FileChoose$ = OpenFileRequester("", "", "*.pb", 0)

MessageRequester("choosen file", FileChoose$) ; #############

	myProg = RunProgram(#PB_Compiler_Home + "compilers/pbcompiler", #DQUOTE$+"--executable"+#DQUOTE$+#DQUOTE$+FileChoose$+#DQUOTE$, "", #PB_Program_Open)    
	Debug myProg
	
	While ProgramRunning(myProg)
		Debug "program running"
	Wend
	
	Debug "runprogram finished"
The compiler seems to run, but no application will be created.
Also I tried a lot of combinations in "parameters" with the same result.
What is wrong?

BTW, the example in the help works as expected.

Re: runprogram - need help

Posted: Mon Jun 04, 2012 7:09 am
by helpy
Hello,

Have a look at the commandline options:

Code: Select all

Quick Help:
-----------

pbcompiler "filename.pb"

Options:
--------
...
-e or --executable "filename": Create an executable to the given filename
...
If you change your code, you can see, that the passed parameters are wrong:

Code: Select all

EnableExplicit

Define FileChoose$, Parameter$, myProg

FileChoose$ = OpenFileRequester("", "", "*.pb", 0)

MessageRequester("choosen file", FileChoose$) ; #############

Parameter$ = #DQUOTE$+"--executable"+#DQUOTE$+#DQUOTE$+FileChoose$+#DQUOTE$
Debug Parameter$

myProg = RunProgram(#PB_Compiler_Home + "compilers/pbcompiler", Parameter$, "", #PB_Program_Open)
Debug myProg

While ProgramRunning(myProg)
  Debug "program running"
Wend

Debug "runprogram finished"
Result of Parameter$:

Code: Select all

"--executable""/path/to/source-code.pb"
Solution: Change your code, so that the Result of Parameter$ looks like this:

Code: Select all

--executable "/path/to/new-executable" "/path/to/source-code.pb"
If you will pass this as Parameter to RunProgram, it should work.

cu,
guido

Re: runprogram - need help

Posted: Tue Jun 05, 2012 6:10 pm
by michel51
Hi helpy,

thanks for your answer.
I tried and tested a lot of combinations for parameters, but an app will not be created.
My last try is here:

Code: Select all

sFile.s = OpenFileRequester("", "", ".pb", 0)
appFile.s = ReplaceString(sFile, ".pb", ".app")
RunProgram(#PB_Compiler_Home + "compilers/pbcompiler", sFile + " -e " + appFile, GetPathPart(sFile), #PB_Program_Wait)
This is from a short snippet, that creates me a resident. It's modified for compiling to an application, but nothing happens.
A resident-file will be compiled.

May be the parameter "-e" or "--executable" buggy and works on Mac not correctly.

Re: runprogram - need help

Posted: Tue Jun 05, 2012 8:23 pm
by J. Baker
Works just fine. Try it with Chr(34). ;)

Code: Select all

sFile.s = OpenFileRequester("", "", ".pb", 0)
appFile.s = ReplaceString(sFile, ".pb", ".app")
RunProgram(#PB_Compiler_Home + "compilers/pbcompiler", Chr(34) + sFile + Chr(34) + " -e " + Chr(34) + appFile + Chr(34), GetPathPart(sFile), #PB_Program_Wait)

Re: runprogram - need help

Posted: Tue Jun 05, 2012 9:23 pm
by michel51
J. Baker wrote:Works just fine. Try it with Chr(34). ;)

Code: Select all

sFile.s = OpenFileRequester("", "", ".pb", 0)
appFile.s = ReplaceString(sFile, ".pb", ".app")
RunProgram(#PB_Compiler_Home + "compilers/pbcompiler", Chr(34) + sFile + Chr(34) + " -e " + Chr(34) + appFile + Chr(34), GetPathPart(sFile), #PB_Program_Wait)
Hmmm... tried, but nothing happens.
Don't know, what is wrong or missing (?)

Re: runprogram - need help

Posted: Tue Jun 05, 2012 9:58 pm
by helpy
Is the source file correct? Maybe the compiler does not finish creating the application because of an syntax error?

Re: runprogram - need help

Posted: Tue Jun 05, 2012 10:08 pm
by michel51
I think, I got it :!:

The code really works as expected.
In the code I used for testing I have used the compiler constant "#PB_Editor_CreateExecutable". This constant is useful for testing if I compiled a source to an application from IDE or if I run the code in IDE (compile/run).
But in this case the constant generates an error ( "Constant #PB_Editor_CreateExecutable not found").
The same if I try to compile in command line terminal.

Hmm, looks like a bug, because the compiler is the same in all cases.
I will further try it and eventually post an bug later.

Re: runprogram - need help

Posted: Tue Jun 05, 2012 10:22 pm
by helpy
It is not a bug!

The constants #PB_Editor_CompileCount, #PB_Editor_BuildCount, #PB_Editor_CreateExecutable are special EDITOR constants, which only work, when compiling from the editor! Have a look at the PureBasic documentation:

==> http://www.purebasic.com/documentation/ ... piler.html

cu,
guido

Re: runprogram - need help

Posted: Tue Jun 05, 2012 11:59 pm
by J. Baker
michel51 wrote:
J. Baker wrote:Works just fine. Try it with Chr(34). ;)

Code: Select all

sFile.s = OpenFileRequester("", "", ".pb", 0)
appFile.s = ReplaceString(sFile, ".pb", ".app")
RunProgram(#PB_Compiler_Home + "compilers/pbcompiler", Chr(34) + sFile + Chr(34) + " -e " + Chr(34) + appFile + Chr(34), GetPathPart(sFile), #PB_Program_Wait)
Hmmm... tried, but nothing happens.
Don't know, what is wrong or missing (?)
Don't copy and paste from Safari. It doesn't work. Use Firefox. ;)

If that's indeed what you did or not.

Re: runprogram - need help

Posted: Wed Jun 06, 2012 1:00 pm
by michel51
J. Baker wrote: Don't copy and paste from Safari. It doesn't work. Use Firefox. ;)

If that's indeed what you did or not.
I know that. I use another way for "copy and paste" from Safari.

Re: runprogram - need help

Posted: Wed Jun 06, 2012 1:07 pm
by michel51
helpy wrote:It is not a bug!

The constants #PB_Editor_CompileCount, #PB_Editor_BuildCount, #PB_Editor_CreateExecutable are special EDITOR constants, which only work, when compiling from the editor! Have a look at the PureBasic documentation:

==> http://www.purebasic.com/documentation/ ... piler.html

cu,
guido
You're right. But as I've said above the source with this constants are testing codes form the past.
And till now I don't needed runprogram in this way.
But now I know that and I will avoid this mistake from now on.
Thanks for your help.