expect: detect a spawned process is still alive and not hung

tcl

    Next

  • 1. Convert a canvas contents into an image?
    Hi all, I want to convert all the drawings of a canvas widget (only plain canvas items and no embedded windows :-)) into an image (anything from tk photo to png, I don't really have a preference...) Is there an extension that does this? I know about tkprint (which I haven't tested at all), but I need something that can be freely used (i.e. BSD, LGPL license). I cannot use tkprint, as I want to include it in an app for a research project and tkprint's license is unclear. Currently I am using the canvas' postscript generation facilities, but its somewhat difficult for users to convert the generated postscript into image formats that are not vector-based... George
  • 2. OT: Let's hear some music
    Hello out there, I am in search of a (music) synthesizer which - can accept scanned 'music sheets' (not sure about the term - in German we call it 'partitur') and - play each voice / instrument It needn't be freeware, but shouldn't cost a fortune either (it's just for hobby). Anybody knows, if such a beast exists for Windows and/or Linux? Thanks Helmut Giese
  • 3. Disabled buttons stipple pattern
    This is on Tk 8.4.6 Is there any way of preventing disabled buttons from displaying a stipple pattern over the image in a compound button ? I can control the stipple on the text using -disabledforeground I have even been taking a look at the tkButton.c source code but I cant seem to find a way without modifying the C code itself. Thanks!

Re: expect: detect a spawned process is still alive and not hung

Postby Don Libes » Sun, 27 Jul 2003 00:40:49 GMT

 XXXX@XXXXX.COM  (TingChong) writes:


That's a very vague term.  The OS has no such label for processes, so
you'll have to elaborate on exactly what you mean by "hung".

Don

Re: expect: detect a spawned process is still alive and not hung

Postby Don Libes » Tue, 29 Jul 2003 23:15:02 GMT

"alive" is not well defined either. But if you "expect eof", most
expect scripts consider the process dead.  Technically, that's not
true - the process can enter the zombie state and then when you do a
wait on the process, it finally disappears from the system.  Bottom
line: choose the definition which best suits your need.

Don


 XXXX@XXXXX.COM  (TingChong) writes:



Re: expect: detect a spawned process is still alive and not hung

Postby Chang Li » Thu, 31 Jul 2003 12:05:03 GMT






The standard output and input of spawned process are channels connect to
expect and send
commands in the main Expect program.

main program                  spawned program
expect   ...                         puts ...
send ...                              gets stdin ...

you can display hourglass in the spawned program.

Chang








Re: expect: detect a spawned process is still alive and not hung

Postby ma7777772 » Thu, 31 Jul 2003 13:35:18 GMT

Active : all states before the function is exited (e.g. ready or
suspended or delayed states).




Re: expect: detect a spawned process is still alive and not hung

Postby Don Libes » Fri, 01 Aug 2003 00:44:00 GMT

If that's really your definition, you can use "exp_wait".  However,
it's generally sufficient (and simpler) to wait for an eof.  As I
recall your earlier code fragment did exactly that already - so I'm
wondering if I missed reading something between the lines?

Don


 XXXX@XXXXX.COM  (TingChong) writes:



Similar Threads:

1.Expect: spawn telnet doesn't work if I spawn from process which is forked

nikolao wrote:
> Hi,
> 
> I have a problem which happens on my ubuntu machine, and on my freebsd
> 7.2 works perfectly well. In my script I fork some processes and those
> processes are trying to connect to some network nodes and do some
> things. Here is part of the script code:
> 
> set timeout 20
> 
> proc start_client {} {
> 	global maxclient
> 	global targets
> 	set n [llength $targets]
> 	if {$n < $maxclient} {
> 		set maxclient $n
> 	}
>         foreach client $targets
> 		if {[fork] == 0} {
> 			disconnect
>                         log_file logs/$client.log
>                         send_log "$client started at [timestamp]"
> 			client_body $client
>                         log_file
> 		}
> 	}
>         #parent waits that children finish, here I use after command
>         #but in original I do something else
>         after 1000000
> }
> 
> proc client_body {ip} {
> 	global spawn_id
> 	set id [spawn telnet  $ip]
> 	set login_status [login_node "username" "password"]
> 	if { $login_status == -1 } {
> 		puts "$ip: invalid username or password"
> 		return -1
> 	} elseif { $login_status == 1 } {
>                 execute_command_on_remote_node
> 	}
>         exit
> }
> 
> proc login_user {user password} {
> 	global timeout
> 
> 	expect {
> 		timeout  { return 0 }
> 		"Username:"  { send "$user\r" }
> 	}
> 	expect {
> 		timeout { return 0 }
> 		"Password:"  { send "$password\r" }
> 	}
> 	expect {
> 		"Username or password invalid!"  { return -1 }
> 		"Fail" { return -1 }
> 		">"  { }
> 	}
>         return 1
> }
> 
> 
> As I can trace execution of script, it enters login_user procedure,
> and then login_user returns 0 from the first expect statement, altough
> I can telnet to targets. What is really strange, is that, if I do not
> fork processes and spawn from parent, my script works. And what is
> more strange, my forked script works perfectly on my freebsd 7.2
> machine.

1.
Is there a reason to fork like mad? ( you could use
[exp_background -i $spawn_id] instead
and have all [spawn]s in one expect process.

2.
You expect "Username:" and "Password:"
most implementations send "..name: " and "...word: "
notice the trailing space.

Not expecting this space will lead to subtle errors:
i.e. premature sending of the reply.

3.
what is in the input buffer?
( change the {return 0} to {expect -re .* ; parray expect_out ; return 0 }

uwe


2.Expect: spawn telnet doesn't work if I spawn from process which is forked

Hi,

I have a problem which happens on my ubuntu machine, and on my freebsd
7.2 works perfectly well. In my script I fork some processes and those
processes are trying to connect to some network nodes and do some
things. Here is part of the script code:

set timeout 20

proc start_client {} {
	global maxclient
	global targets
	set n [llength $targets]
	if {$n < $maxclient} {
		set maxclient $n
	}
        foreach client $targets
		if {[fork] == 0} {
			disconnect
                        log_file logs/$client.log
                        send_log "$client started at [timestamp]"
			client_body $client
                        log_file
		}
	}
        #parent waits that children finish, here I use after command
        #but in original I do something else
        after 1000000
}

proc client_body {ip} {
	global spawn_id
	set id [spawn telnet  $ip]
	set login_status [login_node "username" "password"]
	if { $login_status == -1 } {
		puts "$ip: invalid username or password"
		return -1
	} elseif { $login_status == 1 } {
                execute_command_on_remote_node
	}
        exit
}

proc login_user {user password} {
	global timeout

	expect {
		timeout  { return 0 }
		"Username:"  { send "$user\r" }
	}
	expect {
		timeout { return 0 }
		"Password:"  { send "$password\r" }
	}
	expect {
		"Username or password invalid!"  { return -1 }
		"Fail" { return -1 }
		">"  { }
	}
        return 1
}


As I can trace execution of script, it enters login_user procedure,
and then login_user returns 0 from the first expect statement, altough
I can telnet to targets. What is really strange, is that, if I do not
fork processes and spawn from parent, my script works. And what is
more strange, my forked script works perfectly on my freebsd 7.2
machine.

3.Expect on windows - matching output of a process spawned "outside" expect

Karthick wrote:
> On May 24, 2:49 am, David Gravereaux < XXXX@XXXXX.COM > wrote:
>> Karthick wrote:
>>
>> ...
>>
>>> I do not understand how I can retrieve the value of the hello.exe
>>> process.
>> You can't.  There is a bug in the process management of the debugger
>> routine that ignores ConsoleAPI calls made by other processes.  In this
>> case, the other process is the one you're interested in, rather than the
>> one you spawned.
>>
>> To fix, spawn the process you are interested in as you showed works.
> 
> Hi David,
> 
> I was going through the bug list in SourceForge to understand what you
> said better.. but couldn't find an entry that seems to fit (I could
> have missed it though).
> 
> Can you let me know whether, is this an issue only with windows, or
> with linux version of expect as well?
> 
> Thanks for your help
> 
> Regards,
> Karthick


Just windows.  I'm sure it would be easy to fix, though, given the 
proper dev environment.  The guts are found in the ConsoleDebugger C++ 
class for the threadHandlerProc member function, I think.  When a debug 
event for a process creation happens, it stores the "procinfo" to a 
linkedlist and uses it as an association for any other events that will 
take place after it.  The bug is in there, because it apparently isn't 
finding the "procinfo" or some other logic error.

A perfect example would be using Expect to spawn cvs.exe which will 
launch ssh.exe.  You most definitely want to catch the output of ssh as 
well as cvs so you can login correctly.

The source for E4W is available from Jeff Hobbs.  Just ask him.  There 
was a link he gave about 4 years ago, but can't find it.

4.Expect on windows - matching output of a process spawned "outside" expect

Hi all,

I'm trying to learn expect with a few experiments.. I'm on Expect 5.43
+ Tcl 8.5.7.0 on windows.

I have an hello.exe file compiled from the following C++ source:
#include <iostream>

int main(int argc, char *argv[])
{
   char msg[100];
   std::cout << "Hello" << std::endl;
   std::cin >> msg;
   std::cout << "You said " << msg << std::endl;

   return 0;
}

The following expect script works correctly:
package require Expect

console show
set exp::winnt_debug 1
exp_log_user 0

exp_spawn hello
expect {
   "Hello" {
      puts "Got hello there!"
      exp_send "Hi\r"
      exp_continue
   }
   "You said Hi" {
      puts "Worked ok"
      exp_exit
   }
   timeout {puts "Timed out"}
}

I'm now trying to do the following:
a. Start a shell.
b. Invoke hello.exe in that shell.
c. Match the output of hello.exe.

So I modified the script to:
package require Expect

console show
set exp::winnt_debug 1
exp_log_user 0

# Changed the following two lines
exp_spawn cmd.exe
exp_send "hello\r"
expect {
   "Hello" {
      puts "Got hello there!"
      exp_send "Hi\r"
      exp_continue
   }
   "You said Hi" {
      puts "Worked ok"
      exp_exit
   }
   timeout {puts "Timed out"}
}

I get time out error now, probably because expect is trying to match
the output of cmd.exe, but it needs to instead match the output of
hello.exe. I looked up the documentation of the -i flag to expect, but
I do not understand how I can retrieve the value of the hello.exe
process.

Thanks for any help..

Regards,
Karthick

5.expect: expect of a spawn process in another routine

Is it ok to have the expect of a spawn process in another routine?
e.g. I have the expect in proc spinLock but the process is spawned in
proc waitForTape.
I have this bug that spawned process is time out but I don't
understand why?

proc spinLock { } {
    puts "please wait..."
    set timeout 10000
    expect {
        timeout {
            puts "timeout"
        }
        eof {
            puts "process end"
        }
        "*Error *" {
            puts "Received Error while performing a loop"
        }
        default {
            puts "unknown status"
        }
    }
}

proc waitForTape {} {
    global tapeDevice

    puts "Please insert a tape and press the <Enter> key to continue."
    set status 0
    while { $status == 0 } {
        gets stdin line
        #check tape status
        set tapeStatus ""
        if {[catch {spawn /usr/bin/mt -f $tapeDevice status}
tapeStatus]} {
            puts "tapeStatus $tapeStatus"
            switch -regexp -- $tapeStatus {
                ".*no tape loaded.*" {
                     puts "Error: no tape is loaded.  Please insert a
tape and press the <Enter> key to continue"
                }
                ".*drive offline.*" {
                     puts "Error: drive offline.  Please turn drive
online and press the <Enter> key to continue"
                }
                default {
                     puts "Error: $tapeStatus.  Please fix the problem
and press the <Enter> key to continue"
                }
            }
        } else {
            spinLock
            set status 1
        }
    }
}

6. "telnet localhost" hangs when executing it under expect spawn

7. Expect: Detecting EOF in spawned TCL program

8. redirecting stdin of expect to a spawn process ...



Return to tcl

 

Who is online

Users browsing this forum: No registered users and 7 guest