1

Let's say I have an example perl program, that I can run from CMD (Windows 7) using the command:

perl hello.pl

This outputs:

Hello World!

I can place this in a file using:

perl hello.pl > output.txt

However, what I would like to do, is give it to another application, for this I need it to be fed to a Python application. I give arguments to my Python application using the syntax:

python python.py Arg1 Arg2 Arg3

Assuming my Perl program only gives one parameter, is there a way to run a Python application once it has finished with this parameter?

Alexander Craggs
  • 7,874
  • 4
  • 24
  • 46
  • Not a duplicate, none of the questions work because I am working with CMD. At least, none of the three answers given there work – Alexander Craggs Feb 07 '15 at 15:17
  • 4
    Make your python program read the output from the perl program from `sys.stdin` and pipe the perl program's `stdout` to it: `perl hello.pl | python python.py Arg1 Arg2 Arg3` – martineau Feb 07 '15 at 15:17
  • 1
    Wait, you are able to pipe in cmd? Okay, thanks for the solution. Considering this is a duplicate, should I delete? – Alexander Craggs Feb 07 '15 at 15:18
  • @martineau I re-opened the question so you can turn your comment into an answer. @Popey: Of course you can pipe in `cmd` ... Where have you been? – Sinan Ünür Feb 07 '15 at 15:19
  • Worked for me in cmd console but from one python program to another (I don't have perl installed). – martineau Feb 07 '15 at 15:20
  • Hm, it did work, thanks @martineau - @ Sinan, I've been living in a place without cmd =) – Alexander Craggs Feb 07 '15 at 15:22

1 Answers1

5

Make your python program read the output from the perl program from sys.stdin and pipe the perl program's stdout to it:

perl hello.pl | python python.py Arg1 Arg2 Arg3

I tested this going from one python program to another and in the second python program just did:

import sys

inp = sys.stdin.readline()
print(inp)
martineau
  • 119,623
  • 25
  • 170
  • 301