HI
wondering how does SetEnvironmentVariable works
i try SetEnvironmentVariable("filename","abc123.txt")
then in a batch used echo %filename% but i get no results out !?
thanx
how to get SetEnvironmentVariable in batch script
-
- Addict
- Posts: 2228
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: how to get SetEnvironmentVariable in batch script
Did you start the batch script via RunProgram? Processes inherit environment variables throughout their run hierarchy, so the variables of the parent process are given to the child processes at the beginning.
bye,
Daniel
Daniel
Re: how to get SetEnvironmentVariable in batch script
no i start batch via command line (CMD)
my point is to pass a variable back to a script
Pb progran is just (console mode selected in compiler)
batch is
my point is to pass a variable back to a script
Pb progran is just (console mode selected in compiler)
Code: Select all
SetEnvironmentVariable("filename","abc123.txt")
Code: Select all
@purebasicprog.exe
@echo %filename%
Christos
-
- Addict
- Posts: 2228
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: how to get SetEnvironmentVariable in batch script
You cannot pass it back to the parent process. Use the exit code or stdout to communicate to the batch script then.plouf wrote: ↑Sat Apr 06, 2024 6:51 pm no i start batch via command line (CMD)
my point is to pass a variable back to a script
Pb progran is just (console mode selected in compiler)
batch isCode: Select all
SetEnvironmentVariable("filename","abc123.txt")
Code: Select all
@purebasicprog.exe @echo %filename%
bye,
Daniel
Daniel
Re: how to get SetEnvironmentVariable in batch script
Imho the explanation is correct and there are to possible ways.
1. Make the variable permanent by registry or a tool called setx
2. Create a batch file with @set varname=value and call this batch in your batch file
Maybe this will get you started. (I know, this is no PB code)
The registry keys you should work with are
or
This is where setx stores the definition permanently. Unfortunately you cannot remove a variable with setx, so you have to use the registry like this:
Assuming we want have a variable DEBUG
1. Make the variable permanent by registry or a tool called setx
2. Create a batch file with @set varname=value and call this batch in your batch file
Maybe this will get you started. (I know, this is no PB code)
The registry keys you should work with are
Code: Select all
HKCU\Environment
Code: Select all
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
This is where setx stores the definition permanently. Unfortunately you cannot remove a variable with setx, so you have to use the registry like this:
Assuming we want have a variable DEBUG
Code: Select all
; console commands here
; reg query HKCU\Environment /v DEBUG
; reg add HKCU\Environment /v DEBUG /d
; reg delete HKCU\Environment /v DEBUG /f
; The operation completed successfully.
; /f ... forces the deletion
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home