擅长:python、mysql、java
<p>Python的<code>subprocess</code>库支持管道。以下代码只是对<a href="http://docs.python.org/2/library/subprocess.html#replacing-shell-pipeline" rel="nofollow">documentation example</a>进行了一点修改:</p>
<pre><code>from subprocess import Popen, PIPE
p1 = Popen(["cat", "/home/dbadmin/super_app/data/file_name.spool"],
stdout=PIPE)
p2 = Popen(["vsql", "database", "-U", "user", "-w", "password",
"-c", "copy schema.table from stdin direct no escape null as '\\N'"],
stdin=p1.stdout,
stdout=PIPE)
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
output = p2.communicate()[0]
</code></pre>
<p>我还没有测试以上代码,所以可能有一些拼写错误。在</p>