Have you the way to Refresh PATH in OpenConsole() ?

Just starting out? Need help? Post your questions and find answers here.
sec
Enthusiast
Enthusiast
Posts: 792
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Have you the way to Refresh PATH in OpenConsole() ?

Post by sec »

Have you the way to Refresh PATH in OpenConsole() ?

example:

Code: Select all

OpenConsole()
Debug GetEnvironmentVariable("PATH")

RunProgram("powershell.exe", "$env:PATH += "+#DQUOTE$+";SomeRandomPath"+#DQUOTE$+"", "", #PB_Program_Wait)

Debug GetEnvironmentVariable("PATH") ; this PATH does not refresh
CloseConsole()
infratec
Always Here
Always Here
Posts: 7622
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Have you the way to Refresh PATH in OpenConsole() ?

Post by infratec »

Your code has several problems:

1. If you modify the path in this way, you need to start a new instance of the console.
2. WIth Openconsole you can not rely excute something.

Here is an other way:

Code: Select all

Prog = RunProgram("cmd", "", "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Write | #PB_Program_Error)

*Buffer = AllocateMemory(1024)

WriteProgramStringN(Prog, "@set PATH=%PATH%;C:\your\path\here\")
WriteProgramStringN(Prog, "@echo %PATH%")

Delay(1000)

While AvailableProgramOutput(Prog)
  Length = ReadProgramData(Prog, *Buffer, AvailableProgramOutput(Prog))
  If Length
    Debug PeekS(*Buffer, Length, #PB_UTF8|#PB_ByteLength)
  EndIf
Wend

Delay(2000)
If you check the debug output, you will see the added path entry at the end.
sec
Enthusiast
Enthusiast
Posts: 792
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Re: Have you the way to Refresh PATH in OpenConsole() ?

Post by sec »

Thanks,

Your the code does work well! You always have good solutions 8)

Thanks much :oops: .
Post Reply