Results 1 to 9 of 9
I'm completely stumped as to how to do this. I have an Expect script which spawns a Korn Shell script. The ksh script exports all sorts of variables which I ...
- 06-21-2007 #1Just Joined!
- Join Date
- Jun 2007
- Posts
- 5
Retaining Exported Variables from a Spawned Script Inside of an Expect Script
I'm completely stumped as to how to do this. I have an Expect script which spawns a Korn Shell script. The ksh script exports all sorts of variables which I would normally have access to following the completion of the script on the command line, however, because it's spawned from the Expect script, it seems everything is lost.
Example. If I execute this Expect script from the command line:
Code:#!/usr/bin/expect spawn ksh_script
and then 'echo $TMP_VAR', it's not set.Code:#!/usr/bin/ksh TMP_VAR="Today is warm" export TMP_VAR
Is there a way in in the Expect script to "capture" or somehow tell it to retain any new environment variables from a spawned process? I can't use exec or system which might do what I'm looking for in the Expect script because the ksh script is interactive.
Any help would be greatly appreciated.
- 06-21-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Try to export the variable in your expect script.
Regards
- 06-21-2007 #3Just Joined!
- Join Date
- Jun 2007
- Posts
- 5
TMP_VAR isn't in the list and the variable $TMP_VAR doesn't exist. If I could get the Expect script to even see these exported variables in the ksh script I could then export them.Code:#!/usr/bin/expect spawn ksh_script parray env
- 06-21-2007 #4Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Sorry I misunderstood your question, you can export a variable for the script you're calling but not visa versa. When you call a script, the script runs in another shell.
Regards
- 06-21-2007 #5Just Joined!
- Join Date
- Jun 2007
- Posts
- 5
Right, that's what it seams. Perhaps there's a different approach I might be able to take? Or a command in Expect that won't launch a new subprocess but instead within the same?
I've never encountered an issue like this and it's a complete dead end.
- 06-21-2007 #6Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
A temporary file?
Regards
- 06-22-2007 #7Just Joined!
- Join Date
- Jun 2007
- Posts
- 5
What do you mean?
- 06-22-2007 #8Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Write the value in the ksh script in a temporary file and read the value back with your expect script.
Regards
- 06-22-2007 #9Just Joined!
- Join Date
- Jun 2007
- Posts
- 5
In the actual environment, the one Expect script spawns a ksh script which in turn sources and executes about four other ksh scripts, each of which export a ton variables. Changing all of the ksh scripts involved would be a chore. If I had that luxury, I would clean them all up and not have to write this Expect script in the first place

:drown:


Reply With Quote