Problem in sending inputs to format command using expect

Hi ,

I am not able figure out how to use expect tool to send input to this prompt of format

Searching for disks...done
selecting c0t3d0
[disk formatted]


FORMAT MENU:
        disk       - select a disk
        type       - select (define) a disk type
        partition  - select (define) a partition table
        current    - describe the current disk
        format     - format and analyze the disk
        repair     - repair a defective sector
        label      - write label to the disk
        analyze    - surface analysis
        defect     - defect list management
        backup     - search for backup labels
        verify     - read and display labels
        inquiry    - show vendor, product and revision
        volname    - set 8-character volume name
        !<cmd>     - execute <cmd>, then return
        quit
format>

my try

spawn "format -d c0t3d0"
expect "*format>*"  # I feel something is wrong over here
send "partition/r"

Please help

Is this running over any medium that might add delay, that a line with no linefeed might hang up? Try also expecting the '[disk formatted]' line, as early input will not be lost.

ok , i was able to fix that. btw. can you please let me know how to process pattern that is reptitive . for example

I am setting Free Hog paritition and i have to enter the size of each partition and it would be set to zero. should i create 7 expect function lines and each time send value 0 to it or is there any other way in expect tool ?

What good is a partition of size zero?

Expect runs in tcl, as I recall, so there may be looping constructs in tcl you can include. The man page does not show and flow of control commands: Man Page for expect (all Section 0) - The UNIX and Linux Forums You could generate the expect script using a shell loop. You can generate it on the fly as a named pipe or with commands from stdin in interactive mode:

   The -f flag prefaces a file from which to read commands from.  The flag
   itself is optional as it is only useful when using the \#! notation \(see
   above\),	so  that  other arguments may be supplied on the command line.
   \(When using Expectk, this option is specified as -file.\)

   By default, the command file is read into memory and  executed  in  its
   entirety.   It  is  occasionally  desirable to read files one line at a
   time.  For example, stdin is read this way.  In order  to  force  arbi-
   trary  files  to  be  handled  this  way, use the -b flag.  \(When using
   Expectk, this option is specified as  -buffer.\)Notethatstdio-buffering-
   maystilltakeplacehoweverthisshouldn'tcauseproblemswhenreadingfromafi-
   foorstdin.

   If the string "-" is supplied as a filename,  standard  input  is  read
   instead.  \(Use "./-" to read from a file actually named "-".\)

   The  -i flag causes Expect to interactively prompt for commands instead
   of reading them from a file.  Prompting is terminated via the exit com-
   mand or upon EOF.  See interpreter \(below\) for more information.  -i is
   assumed if neither a command file nor -c is used.  \(When using Expectk,
   this option is specified as -interactive.\)

   --  may	be  used to delimit the end of the options.  This is useful if
   you want to pass an option-like argument  to  your  script  without  it
   being  interpreted  by  Expect.	 This can usefully be placed in the \#!
   line to prevent any flag-like interpretation by Expect.	 For  example,
   the  following  will leave the original arguments \(including the script
   name\) in the variable argv.

   \#!/usr/local/bin/expect --

   Note that  the  usual  [getopt\(3\)](http://www.unix.com/man-page/all/3/getopt/)  and  [execve\(2\)](http://www.unix.com/man-page/all/2/execve/)  conventions  must  be
   observed when adding arguments to the \#! line.