Page 1 of 1

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

Posted: Mon Oct 16, 2023 7:56 am
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()

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

Posted: Mon Oct 16, 2023 7:55 pm
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.

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

Posted: Tue Oct 17, 2023 12:35 am
by sec
Thanks,

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

Thanks much :oops: .