Форум сайта python.su
День добрый, подскажите, пожалуйста, как добиться сто процентной копии работы такого простенького башовского скрипта:
#!/bin/sh while read line; do echo "ERR!$line" done
#!/bin/env perl while (<>) { print; }
Отредактировано Virtul (Май 29, 2013 18:35:38)
Офлайн
import sys data = sys.stdin.read()
Отредактировано s0rg (Май 29, 2013 20:10:24)
Офлайн
while not raw_input() == False: print "ERR!$line"
while True: raw_input() print "ERR!$line"
Отредактировано Rodegast (Май 29, 2013 19:32:15)
Офлайн
2.x:
import sys for x in sys.stdin: print x,
import sys for x in sys.stdin: print(x, end="")
Офлайн
Всем спасибо, но ни один предложенный вариант не сработал, я понятия не имею в чём разница (с консоли всё выглядит одинаково), но работал только вот такой вариант:
#!/bin/env python2.6 import sys line = sys.stdin.readline() while line: print line, line = sys.stdin.readline()
function queryGateway ($gwname, $questions) { global $racktables_gwdir; $execpath = "${racktables_gwdir}/{$gwname}/main"; $dspec = array ( 0 => array ("pipe", "r"), 1 => array ("pipe", "w"), 2 => array ("file", "/dev/null", "a") ); $pipes = array(); $gateway = proc_open ($execpath, $dspec, $pipes); if (!is_resource ($gateway)) return array ('ERR proc_open() failed in ' . __FUNCTION__); foreach ($questions as $q) fwrite ($pipes[0], "$q\n"); fclose ($pipes[0]); $answers = array (); while (!feof($pipes[1])) { $a = fgets ($pipes[1]); if (!strlen ($a)) continue; // Somehow I got a space appended at the end. Kick it. $answers[] = trim ($a); } fclose($pipes[1]); $retval = proc_close ($gateway); if ($retval != 0) throw new RTGatewayError ("gateway failed with code ${retval}"); if (!count ($answers)) throw new RTGatewayError ('no response from gateway'); if (count ($answers) != count ($questions)) throw new RTGatewayError ('protocol violation'); foreach ($answers as $a) if (strpos ($a, 'OK!') !== 0) throw new RTGatewayError ("subcommand failed with status: ${a}"); return $answers; }
#!/bin/env python2.6 import sys while 1: x = sys.stdin.readline() print x,
Отредактировано Virtul (Май 30, 2013 10:44:03)
Офлайн
Virtul
ни один предложенный вариант не сработал, я понятия не имею в чём разница
VirtulЕсть мнение, что это все из-за буфферизации, вам нужно посмотреть в доках php (сам с ним, почти, не работаю) как ее отключить для ваших каналов.
а вот этот код вообще вешает страницу с вызовом queryGateway намертво:
Офлайн