How to make a batch file interactive
-
I'm trying to make an interactive batch file (.cmd) to run under Windows NT. The obvious way is to have a program that displays a prompt and sets an environment variable with the response - the batch file can then access the input value via the environment variable (as %environmentvariable%), however 1) using _setenv() only alters the environment for the current program, so the batch file that ran the program does not see the new variable; conversely 2) altering the registry where the environment variables are kept (HKEY_CURRENT_USER\Environment etc.) has no effect until a new DOS shell is started, so the batch file that ran the program does not see the new variable; 3) the old DOS method of getting the PSP and walking up the environment areas isn't allowed under NT (and there's never enough space in the environment area anyway); If anyone knows how to write a program that can do this, or any other way of making a batch file interactive, I'd love to hear about it. (PS I know that using VBS or some other scripting language is the right way to go, but I need this to run on any NT Server machine, and the CMD processor seems to be the only scripting engine that is guaranteed to be available) Thanks Dave
-
I'm trying to make an interactive batch file (.cmd) to run under Windows NT. The obvious way is to have a program that displays a prompt and sets an environment variable with the response - the batch file can then access the input value via the environment variable (as %environmentvariable%), however 1) using _setenv() only alters the environment for the current program, so the batch file that ran the program does not see the new variable; conversely 2) altering the registry where the environment variables are kept (HKEY_CURRENT_USER\Environment etc.) has no effect until a new DOS shell is started, so the batch file that ran the program does not see the new variable; 3) the old DOS method of getting the PSP and walking up the environment areas isn't allowed under NT (and there's never enough space in the environment area anyway); If anyone knows how to write a program that can do this, or any other way of making a batch file interactive, I'd love to hear about it. (PS I know that using VBS or some other scripting language is the right way to go, but I need this to run on any NT Server machine, and the CMD processor seems to be the only scripting engine that is guaranteed to be available) Thanks Dave
I don't know if modifying parent process' env block is possible. I'd give up setting the result in environment vars directly, instead, I'd write something to dynamically created .bat or .cmd file. If user enters 'foo', the file would look like this: set var=foo Main batch would call this file to make changes. Tomasz Sowinski -- http://www.shooltz.com
-
I don't know if modifying parent process' env block is possible. I'd give up setting the result in environment vars directly, instead, I'd write something to dynamically created .bat or .cmd file. If user enters 'foo', the file would look like this: set var=foo Main batch would call this file to make changes. Tomasz Sowinski -- http://www.shooltz.com
Thanks, but it won't work - when the main batch calls the sub batch the sub batch will set the variable in its own environment, but then it disappears again when the sub batch returns to the main batch. Dave Dave
-
Thanks, but it won't work - when the main batch calls the sub batch the sub batch will set the variable in its own environment, but then it disappears again when the sub batch returns to the main batch. Dave Dave
Are you sure? I've tested this on my XP Pro. When you execute b1, SET displays var with the value of 'foo'.
rem b1.bat
call b2.bat
setrem b2.bat
set var=fooTomasz Sowinski -- http://www.shooltz.com
-
I'm trying to make an interactive batch file (.cmd) to run under Windows NT. The obvious way is to have a program that displays a prompt and sets an environment variable with the response - the batch file can then access the input value via the environment variable (as %environmentvariable%), however 1) using _setenv() only alters the environment for the current program, so the batch file that ran the program does not see the new variable; conversely 2) altering the registry where the environment variables are kept (HKEY_CURRENT_USER\Environment etc.) has no effect until a new DOS shell is started, so the batch file that ran the program does not see the new variable; 3) the old DOS method of getting the PSP and walking up the environment areas isn't allowed under NT (and there's never enough space in the environment area anyway); If anyone knows how to write a program that can do this, or any other way of making a batch file interactive, I'd love to hear about it. (PS I know that using VBS or some other scripting language is the right way to go, but I need this to run on any NT Server machine, and the CMD processor seems to be the only scripting engine that is guaranteed to be available) Thanks Dave