lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> while true do os.execute('echo hello world') end
> 
> cannot be stopped with ^C.

The ^C is caught by the forked process and is never seen by Lua. Try
	while true do os.execute('echo hello ; sleep 5; echo bye') end

When you press ^C, you never see "bye".

Now try hitting ^C on this code:
	while os.execute("echo hello") do end

If you print the return value, you'll see
	true	exit	0
	hello
	true	exit	0
	hello
	true	exit	0
	^Cnil	signal	2

Bottom line: test the return value of os.execute if you want to handle ^C
in forked processes.