Interactive batch in Windows NT
-
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, however 1) using _setenv (I'm in C/C++ here) only alters the environment for the current program, so the batch file that ran the program does not see them; 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 them; 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 intercative, 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 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, however 1) using _setenv (I'm in C/C++ here) only alters the environment for the current program, so the batch file that ran the program does not see them; 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 them; 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 intercative, 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 Dave
Dave - I dont know if you've since found a solution (or if Ive understood the problem), but here's my $AUD 0.02c worth (probably not worth much in other currencies) I would start with :- http://www.pgh.net/~newcomer/processes.htm or http://www.pgh.net/~newcomer/process.htm or go to http://www.pgh.net/~newcomer/mvp\_tips.htm and look for 'asynchronous process notification' these solve the problem of starting (for example) a batch file and reading the console output back into a listbox etc .. from there, the listbox could be parsed looking for certain triggers etc, to get the results.. 'Franky Braem' also has an article on Codeproject entitled 'Redirect' which could be used as a starting point. If thats not what you want 100%, then how about creating a console window using one of the above techniques, and reading (much like screen scraping from it) directly - I have seen examples on doing this, but cant find any to hand right now ... hth Garth
-
Dave - I dont know if you've since found a solution (or if Ive understood the problem), but here's my $AUD 0.02c worth (probably not worth much in other currencies) I would start with :- http://www.pgh.net/~newcomer/processes.htm or http://www.pgh.net/~newcomer/process.htm or go to http://www.pgh.net/~newcomer/mvp\_tips.htm and look for 'asynchronous process notification' these solve the problem of starting (for example) a batch file and reading the console output back into a listbox etc .. from there, the listbox could be parsed looking for certain triggers etc, to get the results.. 'Franky Braem' also has an article on Codeproject entitled 'Redirect' which could be used as a starting point. If thats not what you want 100%, then how about creating a console window using one of the above techniques, and reading (much like screen scraping from it) directly - I have seen examples on doing this, but cant find any to hand right now ... hth Garth
Thanks Garth, but either you've misunderstood the question or I've misunderstood the answer. Basically all I want is a way of putting user interaction into a batch file, such that the user is prompted to enter values which can then be used by subsequent operations in the batch file (ie. passed to other programs as parameters, used in IF constructs, etc.). There is(are) no Windows/windows involved here at all (except for the DOS box that the user runs the batch file in). Thanks for trying anyway. Dave Dave