Page 1 of 1

Force variable evaluation

Posted: Wed Jan 24, 2007 1:51 am
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$)

Posted: Wed Jan 24, 2007 3:54 am
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 

Posted: Wed Jan 24, 2007 5:13 am
by imtcb
Thanks. Not the answer I was hoping for, but thank you none the less!

Posted: Wed Jan 24, 2007 3:13 pm
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...

Posted: Wed Jan 24, 2007 3:21 pm
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$)

Posted: Wed Jan 24, 2007 3:59 pm
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!

Posted: Wed Jan 24, 2007 5:06 pm
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

Posted: Thu Jan 25, 2007 3:50 pm
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