Expect script: using variable to represent filename? 
Author Message
 Expect script: using variable to represent filename?

        I am experimenting with a simple expect script (expect version
5.25.0) to automate an interactive session of mail to alter a mail file.  
The script below works when the filename is explicitly written into it:

spawn mail -f digest5.749
expect "& $"
send "!rm digest5.749\r"
send "s* digest5.749\r"
expect "& $"
send "x\r"
wait

        However, I want it to be able to work with *any* file starting
with the string "digest" because the filename's numeric part may have
changed every time I invoke this script.  Is there a way within expect to
do something like "glob digest*" to return the actual current filename,
then assign this filename to a variable, and substitute the variable for
the filename in the "send" lines?  None of this seems clear in the expect
man page or other documentation I've seen.
                                                        --Donald Davis



Wed, 09 Jun 2004 04:23:59 GMT  
 Expect script: using variable to represent filename?


Quote:
>    I am experimenting with a simple expect script (expect version
>5.25.0) to automate an interactive session of mail to alter a mail file.  
>The script below works when the filename is explicitly written into it:

>spawn mail -f digest5.749
>expect "& $"
>send "!rm digest5.749\r"
>send "s* digest5.749\r"
>expect "& $"
>send "x\r"
>wait

>    However, I want it to be able to work with *any* file starting
>with the string "digest" because the filename's numeric part may have
>changed every time I invoke this script.  Is there a way within expect to
>do something like "glob digest*" to return the actual current filename,
>then assign this filename to a variable, and substitute the variable for
>the filename in the "send" lines?  None of this seems clear in the expect
>man page or other documentation I've seen.
>                                                    --Donald Davis

Does
  set one_file_name [glob digest*]
  spawn mail -f $one_file_name
  expect "& $"
  send "!rm $one_file_name\r"
  send "s* $one_file_name\r"
  expect "& $"
  send "x\r"
  wait
get you closer to what you want?
--


Business:  http://www.Phaseit.net
Personal:  http://starbase.neosoft.com/~claird/home.html



Wed, 09 Jun 2004 07:00:34 GMT  
 Expect script: using variable to represent filename?

Quote:



>>        I am experimenting with a simple expect script (expect version
>>5.25.0) to automate an interactive session of mail to alter a mail file.  
>>The script below works when the filename is explicitly written into it:

>>spawn mail -f digest5.749
>>expect "& $"
>>send "!rm digest5.749\r"
>>send "s* digest5.749\r"
>>expect "& $"
>>send "x\r"
>>wait

>>        However, I want it to be able to work with *any* file starting
>>with the string "digest" because the filename's numeric part may have
>>changed every time I invoke this script.  Is there a way within expect to
>>do something like "glob digest*" to return the actual current filename,
>>then assign this filename to a variable, and substitute the variable for
>>the filename in the "send" lines?  None of this seems clear in the expect
>>man page or other documentation I've seen.
>>                                                        --Donald Davis
>Does
>  set one_file_name [glob digest*]
>  spawn mail -f $one_file_name
>  expect "& $"
>  send "!rm $one_file_name\r"
>  send "s* $one_file_name\r"
>  expect "& $"
>  send "x\r"
>  wait
>get you closer to what you want?

        Yes indeed; works like a charm.  Many thanks.  Where can one find
this kind of syntax information?
                                                        --Donald Davis


Wed, 09 Jun 2004 11:20:38 GMT  
 Expect script: using variable to represent filename?


                        .
                        .
                        .

Quote:
>>Does
>>  set one_file_name [glob digest*]
>>  spawn mail -f $one_file_name
>>  expect "& $"
>>  send "!rm $one_file_name\r"
>>  send "s* $one_file_name\r"
>>  expect "& $"
>>  send "x\r"
>>  wait
>>get you closer to what you want?

>    Yes indeed; works like a charm.  Many thanks.  Where can one find
>this kind of syntax information?
>                                                    --Donald Davis

I don't understand the question.  Does
<URL: http://mini.net/tcl/BeginningTcl >
help?

At some point, you'll want to read
<URL: http://mini.net/tcl/ExploringExpect >.
--


Business:  http://www.Phaseit.net
Personal:  http://starbase.neosoft.com/~claird/home.html



Wed, 09 Jun 2004 11:44:08 GMT  
 Expect script: using variable to represent filename?

Quote:



>                    .
>>>Does
>>>  set one_file_name [glob digest*]
>>>  spawn mail -f $one_file_name
>>>  expect "& $"
>>>  send "!rm $one_file_name\r"
>>>  send "s* $one_file_name\r"
>>>  expect "& $"
>>>  send "x\r"
>>>  wait
>>>get you closer to what you want?

>>        Yes indeed; works like a charm.  Many thanks.  Where can one find
>>this kind of syntax information?
>>                                                        --Donald Davis
>I don't understand the question.  Does
><URL: http://mini.net/tcl/BeginningTcl >
>help?
>At some point, you'll want to read
><URL: http://mini.net/tcl/ExploringExpect >.

        I had already looked at the second URL, including the description
of the "set" command, but the aspect I couldn't find was the "[glob
digest*]" part of the expression, as a way to set the variable without
directly entering a literal value.  Perhaps that would have been obvious
to an experienced programmer (I am very much a novice).

                                                        --Donald Davis



Wed, 09 Jun 2004 12:56:33 GMT  
 Expect script: using variable to represent filename?


                        .
                        .
                        .

Quote:
>>>    Yes indeed; works like a charm.  Many thanks.  Where can one find
>>>this kind of syntax information?
>>>                                                    --Donald Davis

>>I don't understand the question.  Does
>><URL: http://mini.net/tcl/BeginningTcl >
>>help?

>>At some point, you'll want to read
>><URL: http://mini.net/tcl/ExploringExpect >.

>    I had already looked at the second URL, including the description
>of the "set" command, but the aspect I couldn't find was the "[glob
>digest*]" part of the expression, as a way to set the variable without
>directly entering a literal value.  Perhaps that would have been obvious
>to an experienced programmer (I am very much a novice).

>                                                    --Donald Davis

I'm very, very glad you found the [glob] on your
own; that certainly simplified things.

Does <URL: http://mini.net/tcl/BeginningTcl > help?
Tcl's a fine language for a novice to programming;
is that truly an accurate description of you?
--


Business:  http://www.Phaseit.net
Personal:  http://starbase.neosoft.com/~claird/home.html



Sat, 12 Jun 2004 01:17:36 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Using variable filename(!FILENAME)

2. Set expect script variables via a korn shell script

3. How to run the expect script using TCL oe expect 5.21

4. How to Specify Variable FileName(!FileName)In Report

5. Using Variable Filenames and Paths

6. Starting Multiple Expect Scripts from a Single Expect Script

7. Expect scripts within expect scripts

8. Expect script calling Expect script

9. variable used as filename

10. Setting additional environment variables WITHIN an expect script

11. Newbie - passing variable number of vars to expect script

12. Maintaining Environment Variables - Expect Log_File Script

 

 
Powered by phpBB® Forum Software