Force variable evaluation

Just starting out? Need help? Post your questions and find answers here.
imtcb
User
User
Posts: 12
Joined: Sun Jan 21, 2007 6:37 am

Force variable evaluation

Post by imtcb »

I have looked through the help file and the forum and I just can't figure it out. How can I force evaluation of a variable so I can use the variable value in a listname declaration?

Code: Select all

temp$ = SomeProcedureCallReturnValue()
NewList temp$()
This creates the list with the name temp$, not the value that was returned from the procedure.
Is there a way to make this work?

Also, I asked a question in my other thread that was a little off topic and it didn't get an answer. Is there any way to capture the errorlevel / exitcode from xcopy? I researched the Process library and even used the sample code but I just can't get it to capture anything out of xcopy. Not even the help text from using /?.
Here is the sample code with only the program changed to use xcopy instead:

Code: Select all

  Compiler = RunProgram("c:\windows\system32\xcopy.exe", "/?", "", #PB_Program_Open|#PB_Program_Read)
  Output$ = ""
  If Compiler  
    While ProgramRunning(Compiler)
      Output$ + ReadProgramString(Compiler) + Chr(13)
    Wend
    Output$ + Chr(13) + Chr(13)
    Output$ + "Exitcode: " + Str(ProgramExitCode(Compiler))     
  EndIf
  MessageRequester("Output", Output$)
Heathen
Enthusiast
Enthusiast
Posts: 498
Joined: Tue Sep 27, 2005 6:54 pm
Location: At my pc coding..

Post by Heathen »

For your first question, pb doesnt work that way. When it says "name" in the helpfile, its not refering to a string... It's like declaring an array without specifying fields.

ie

Code: Select all

NewList mylist()
For x = 1 To 10
  AddElement(mylist())
  mylist() = x
Next x
ForEach mylist()
  Debug mylist()
Next 
I love Purebasic.
imtcb
User
User
Posts: 12
Joined: Sun Jan 21, 2007 6:37 am

Post by imtcb »

Thanks. Not the answer I was hoping for, but thank you none the less!
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

it's the same as in most real compiler-languages:

the name of any variable/structure/function/etc. is just a placeholder for some pointer.
it's a word in the code to make it easy to read for the programmer,
but in the .exe it's only a number, no name left anywhere...
oh... and have a nice day.
User avatar
blueb
Addict
Addict
Posts: 1111
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Post by blueb »

Question #2...

Don't know if this is what you are looking for...

Code: Select all

OpenConsole()
 Compiler = RunProgram("c:\windows\system32\xcopy.exe", "/?", "", #PB_Program_Open|#PB_Program_Read) 
CloseConsole()
  Output$ = "" 
  If Compiler  
    While ProgramRunning(Compiler) 
      Output$ + ReadProgramString(Compiler) + Chr(13) 
    Wend 
    Output$ + Chr(13) + Chr(13) 
    Output$ + "Exitcode: " + Str(ProgramExitCode(Compiler))      
  EndIf 
  MessageRequester("Output", Output$)
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
imtcb
User
User
Posts: 12
Joined: Sun Jan 21, 2007 6:37 am

Post by imtcb »

Thank you both!

@Kaeru Gaman - This is my first attempt at programming. I have used scripting languages in the past, and one of them allowed forced evaluation like I was trying to do. Looking through the help file I think I will be able to make a structure work for me.

@blueb - Yes! This in fact does work! However, I spent about 4 hours yesterday coding off of an example in my other thread which listed the directories recursively. I have it working flawlessly now, and it has way more flexibility than xcopy does. Thank you though for helping me, I do appreciate it!
Clutch
User
User
Posts: 52
Joined: Sun Nov 26, 2006 6:11 am
Location: South Florida

Post by Clutch »

blueb wrote:Question #2...

Don't know if this is what you are looking for...

Code: Select all

OpenConsole()
 Compiler = RunProgram("c:\windows\system32\xcopy.exe", "/?", "", #PB_Program_Open|#PB_Program_Read) 
CloseConsole()
  Output$ = "" 
  If Compiler  
    While ProgramRunning(Compiler) 
      Output$ + ReadProgramString(Compiler) + Chr(13) 
    Wend 
    Output$ + Chr(13) + Chr(13) 
    Output$ + "Exitcode: " + Str(ProgramExitCode(Compiler))      
  EndIf 
  MessageRequester("Output", Output$)
:shock: blueb, thanks very much for this! I spent a couple days trying to redirect PsExec's output and ultimately gave up figuring it wasn't possible (see here). Using your modifications, it now works perfectly! Can you explain why adding Open/CloseConsole() works?

Thanks again! :D
"Ahead one third... ahead two thirds... Full ahead flank
And out from the belly of the whale came a prophet, Amen"
User avatar
blueb
Addict
Addict
Posts: 1111
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Post by blueb »

I'm not exactly sure, but you might look in the MS Platform SDK and look under "consoles".

I think it has to do with character based programs (like XCopy) needing a new process space.

--blueb
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Post Reply