[done] RunProgram whis text

Just starting out? Need help? Post your questions and find answers here.
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

[done] RunProgram whis text

Post by mestnyi »

They made comments to me, so I'm creating a new topic.

Code: Select all

text$ = "Window_1 = OpenWindow(#PB_Any, 0, 0, 200, 200, "+Chr('"')+"window_1"+Chr('"')+ ")" + #LF$ +
"Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow"

RunProgram(#PB_Compiler_Home+"/Compilers/pbcompiler", "/EXE"+ text$, "", #PB_Program_Open|#PB_Program_Wait )
;RunProgram(#PB_Compiler_Home+"/Compilers/pbcompiler", text$ + " /EXE", "", #PB_Program_Open|#PB_Program_Wait )
        
AZJIO wrote: Mon Mar 03, 2025 5:13 am 1. This topic is to correct documentation errors, and not to resolve other issues.
2. This is not autoit3, so it is impossible to do this. Firstly, you need to save the file, and secondly, you cannot add the compiler to your program, since the license does not allow.
For example, in pureform, in icedesign there is a preview function, I thought it was implemented this way.
Last edited by mestnyi on Thu Mar 06, 2025 12:41 pm, edited 1 time in total.
AZJIO
Addict
Addict
Posts: 2141
Joined: Sun May 14, 2017 1:48 am

Re: RunProgram whis text

Post by AZJIO »

mestnyi wrote: Mon Mar 03, 2025 9:29 am For example, in pureform, in icedesign there is a preview function, I thought it was implemented this way.
Looking at source code and compiling are different things.
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: RunProgram whis text

Post by infratec »

Simply try to run the output in a dos-box:

Code: Select all

text$ = "Window_1 = OpenWindow(#PB_Any, 0, 0, 200, 200, "+Chr('"')+"window_1"+Chr('"')+ ")" + #LF$ +
"Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow"

Debug #PB_Compiler_Home+"/Compilers/pbcompiler" + " " + "/EXE"+ text$
Axolotl
Enthusiast
Enthusiast
Posts: 798
Joined: Wed Dec 31, 2008 3:36 pm

Re: RunProgram whis text

Post by Axolotl »

I would have thought that the compiler always needs a file ?

Code: Select all

Usage: pbcompiler “Filename”
Even if it is one line and the compiler is enclosed with doublequotes, the following error message is displayed:
Command Line:

Code: Select all

"C:\Program Files\PureBasic\/Compilers/pbcompiler" /EXE Window_1 = OpenWindow(#PB_Any, 0, 0, 200, 200, "window_1") : Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
Results in

Code: Select all

C:\Users\andre>"C:\Program Files\PureBasic\/Compilers/pbcompiler" /EXE Window_1 = OpenWindow(#PB_Any, 0, 0, 200, 200, "window_1") : Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
PureBasic 6.20 (Windows - x64)
Compiling WaitWindowEvent()=#PB_Event_CloseWindow
Loading external libraries...
Error: File not found (WaitWindowEvent()=#PB_Event_CloseWindow).
If you also enclose the entire parameter in double quotes, you get this:

Code: Select all

PureBasic 6.20 (Windows - x64) - (c) 2025 Fantaisie Software
A source filename need to be specified.
Type 'pbcompiler /?' for quick help.
So my suggestion: Save the text in a file and call that one.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: RunProgram whis text

Post by mestnyi »

infratec wrote: Mon Mar 03, 2025 10:12 am Simply try to run the output in a dos-box:

Code: Select all

text$ = "Window_1 = OpenWindow(#PB_Any, 0, 0, 200, 200, "+Chr('"')+"window_1"+Chr('"')+ ")" + #LF$ +
"Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow"

Debug #PB_Compiler_Home+"/Compilers/pbcompiler" + " " + "/EXE"+ text$
I did as you said and what did you mean by that? :)
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: RunProgram whis text

Post by mestnyi »

Axolotl wrote: Mon Mar 03, 2025 11:34 am So my suggestion: Save the text in a file and call that one.
I didn't want to save it, is there really no other solution? :oops:
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: RunProgram whis text

Post by mestnyi »

AZJIO wrote: Mon Mar 03, 2025 10:03 am
mestnyi wrote: Mon Mar 03, 2025 9:29 am For example, in pureform, in icedesign there is a preview function, I thought it was implemented this way.
Looking at source code and compiling are different things.
I don't understand what you mean.
it would seem a simple task, but there is not even any desire to continue working.
Axolotl
Enthusiast
Enthusiast
Posts: 798
Joined: Wed Dec 31, 2008 3:36 pm

Re: RunProgram whis text

Post by Axolotl »

mestnyi wrote: Mon Mar 03, 2025 4:49 pm I didn't want to save it, is there really no other solution? :oops:
I know, so I checked this file

Code: Select all

; #PB_Compiler_Home + "SDK\CompilerInterface.txt"
for some hints.
Controlling the compiler /STANDBY with e.g. 'WriteProgramStringN()'
But there is always a source filename involved. Sorry, unfortunately I can't help you any better.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: RunProgram whis text

Post by ChrisR »

I saw that my application was quoted.
For the preview, the generated code is written to a temporary file, compiled and then executed, as Axolotl wrote.
With a BIG thanks for the speed of the ASM compiler, to have the preview in less than 2 seconds.

Seeing the help, I didn't even try to do it any other way, with a string as parameter, a virtual NTFS file.
In all cases, creating a temporary file is the simplest and easiest way.
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: RunProgram whis text

Post by mestnyi »

ChrisR wrote: Mon Mar 03, 2025 10:00 pm I saw that my application was quoted.
For the preview, the generated code is written to a temporary file, compiled and then executed, as Axolotl wrote.
With a BIG thanks for the speed of the ASM compiler, to have the preview in less than 2 seconds.

Seeing the help, I didn't even try to do it any other way, with a string as parameter, a virtual NTFS file.
In all cases, creating a temporary file is the simplest and easiest way.
Can you give me the code for how you did it?
AZJIO
Addict
Addict
Posts: 2141
Joined: Sun May 14, 2017 1:48 am

Re: RunProgram whis text

Post by AZJIO »

Code: Select all

; Execute the source code on the clipboard.

EnableExplicit

Procedure.s TmpFile(DirName$ = "", Prefix$ = "~", Ext$ = ".tmp", RandomLength = 7)
	Protected TmpName$
	
	If RandomLength < 4 Or RandomLength > 130
		RandomLength = 7
	EndIf
	If Not Asc(DirName$) Or FileSize(DirName$) = -1
		DirName$ = GetTemporaryDirectory()
	EndIf
	
	If Not CheckFilename(Prefix$)
		Prefix$ = "~"
	EndIf
	If Not CheckFilename(Ext$)
		Ext$ = ".tmp"
	EndIf
	
	If Right(DirName$, 1) <> #PS$
		DirName$ + #PS$
	EndIf
	If Asc(Ext$) And Left(Ext$, 1) <> "."
		Ext$ = "." + Ext$
	EndIf
	
	Repeat
		TmpName$ = ""
		While Len(TmpName$) < RandomLength
			TmpName$ + Chr(Random(122, 97))
		Wend
		TmpName$ = DirName$ + Prefix$ + TmpName$ + Ext$
	Until FileSize(TmpName$) = -1
	
	ProcedureReturn TmpName$
EndProcedure

Define path$, code$, id_file, compiler$
path$ = TmpFile("", "", ".pb")
code$ = GetClipboardText()


id_file = CreateFile(#PB_Any, path$)
If id_file
	WriteStringFormat(id_file, #PB_UTF8)
	WriteString(id_file, code$)
	CloseFile(id_file)
EndIf

If FileSize(path$) < 0
	MessageRequester("Error", "Source not found" + #CRLF$ + #CRLF$ + path$)
	End
EndIf

compiler$ = #PB_Compiler_Home + "Compilers\pbcompiler.exe"
; Debug compiler$
; Debug FileSize(compiler$)
; Debug path$
; Debug FileSize(path$)
RunProgram(compiler$,
           #DQUOTE$ + path$ + #DQUOTE$ + " /DPIAWARE -q /EXE " + #DQUOTE$ + path$ + ".exe" + #DQUOTE$, "",
           #PB_Program_Wait | #PB_Program_Hide) ; #PB_Program_Hide - error output problem
If FileSize(path$ + ".exe") > 0
	RunProgram(path$ + ".exe")
Else
	MessageRequester("Compilation error", "Failed to get the executable file" + #CRLF$ + #CRLF$ + path$ + ".exe")
EndIf
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: RunProgram whis text

Post by infratec »

mestnyi wrote: Mon Mar 03, 2025 4:47 pm
infratec wrote: Mon Mar 03, 2025 10:12 am Simply try to run the output in a dos-box:

Code: Select all

text$ = "Window_1 = OpenWindow(#PB_Any, 0, 0, 200, 200, "+Chr('"')+"window_1"+Chr('"')+ ")" + #LF$ +
"Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow"

Debug #PB_Compiler_Home+"/Compilers/pbcompiler" + " " + "/EXE"+ text$
I did as you said and what did you mean by that? :)
Then you will see that it is not working as you are expecting.
AZJIO
Addict
Addict
Posts: 2141
Joined: Sun May 14, 2017 1:48 am

Re: RunProgram whis text

Post by AZJIO »

mestnyi wrote: Mon Mar 03, 2025 9:29 am

Code: Select all

#PB_Compiler_Home+"/Compilers/pbcompiler"
All constants and functions that are paths ALWAYS have "\" in them at the end of the line. Therefore, you should never start the second part of a file path with this character.
mestnyi wrote: Mon Mar 03, 2025 9:29 am

Code: Select all

"/EXE"+ text$
The path in the parameters should ALWAYS be in quotes.
Axolotl
Enthusiast
Enthusiast
Posts: 798
Joined: Wed Dec 31, 2008 3:36 pm

Re: RunProgram whis text

Post by Axolotl »

@AZJIO:
You may have overlooked the fact that he does not want to save the source code. But I think you have confirmed that it (only) works with a (temp) file.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
AZJIO
Addict
Addict
Posts: 2141
Joined: Sun May 14, 2017 1:48 am

Re: RunProgram whis text

Post by AZJIO »

Axolotl wrote: Wed Mar 05, 2025 12:24 pm @AZJIO:
You may have overlooked
Read the first message in this topic. It says that I didn't miss it :mrgreen:
Post Reply