Article View: comp.os.msdos.programmer
Article #1239Re: Environment variables when using system(...) command
From: Eli Boaz
Date: Wed, 02 Sep 1992 20:52
Date: Wed, 02 Sep 1992 20:52
30 lines
1956 bytes
1956 bytes
In article <1992Sep1.194508.10559@sactoh0.sac.ca.us> sap@sactoh0.sac.ca.us (Stephan A. Puga) writes: >If an environment variable is set before a program is run and the >program makes use of the system(...) command, how can I use the >environment variable in the system command? I am writing a program >to be used on a network and there is a variable "username" set >before the program is run (this variable by the way is very >important to how WordPerfect 5.1 runs on the network), my program >invokes WP51 and tries to pass it the username variable, but it >doesn't work! Is there no way I can get the new "local" command >shell to use the same "old" command shell's variables? Well, first off, you need to get the environment variable into a program variable. (I do not know how to do this in C, but getenv() looks like it would be the correct choice under Turbo C/Borland C) Then, concatonate the program variable (say "john") so that your system command will look like: system(syscmd); where syscmd="d:\wp51dir\wp.exe john ..." or something similar... I have done something similar to this a while back while writing a login program and it's utilities for my pc in Turbo Pascal. hope this helps, -- Eli Boaz | Line noise provide by S.W. Bell Telephone! raistlin@wixer.cactus.org | "Anyone not wearing 2 million sunblock is ...!cactus.org!wixer!raistlin | going to have a REAL BAD DAY, get it?" -T2 ----------------------------------------------------------------------------
Technical Details
Message-ID:
<1992Sep2.205255.23847@wixer.cactus.org>Path:
arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!milano!cactus.org!wixer!raistlinReferences:
<1992Sep1.194508.10559@sactoh0.sac.ca.us>Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!milano!cactus.org!wixer!raistlin From: raistlin@wixer.cactus.org (Eli Boaz) Subject: Re: Environment variables when using system(...) command Message-ID: <1992Sep2.205255.23847@wixer.cactus.org> Organization: Real/Time Communications References: <1992Sep1.194508.10559@sactoh0.sac.ca.us> Date: Wed, 2 Sep 92 20:52:55 GMT Lines: 30