Changeset

46:b5d6e443e571

raw: If using --stdin and not --interactive then buffer all data before connecting, more reliable in a non-interactive environment
author Matthew Wild <mwild1@gmail.com>
date Tue, 22 Feb 2011 20:52:22 +0000
parents 45:36f5bf718d3c
children 47:d4650cc6bb3f 48:8206f3369d37
files clix/raw.lua
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/clix/raw.lua	Tue Dec 14 20:18:56 2010 +0000
+++ b/clix/raw.lua	Tue Feb 22 20:52:22 2011 +0000
@@ -6,9 +6,15 @@
 		print("Send/receive raw XML to/from the server");
 		return;
 	end
+	
+	local send_xml;
+	if opts.stdin then
+		send_xml = io.read("*a");
+	end
+	
 	local function on_connect(conn)
-		conn:hook("incoming-raw", print);
-		if opts.interactive or opts.stdin then
+		conn:hook("incoming-raw", function (data) print(data) end);
+		if opts.interactive then
 			local stdin = {
 				getfd = function () return 0; end;
 				dirty = function (self) return false; end;
@@ -33,7 +39,11 @@
 				onincoming = on_incoming, ondisconnect = function () end
 				}, "*l");
 		else
-			conn:send(table.concat(arg, " "));
+			if send_xml then
+				conn:send(send_xml);
+			else
+				conn:send(table.concat(arg, " "));
+			end
 			conn:close();
 		end