Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing to STDIN? 1

Status
Not open for further replies.

jvchamary

Programmer
Feb 4, 2004
9
0
0
CH
Hello!

Quick question... I'm currently using a program that asks for user input via STDIN, but I'd like to run it non-interactively from a perl script. I had hoped that the following would work, but it doesn't...
Code:
print(STDIN "input\n");
Thanks in advance for your help!

JVC.
 
I do not understand your question. Specifically:

but I'd like to run it non-interactively from a perl script.

What do you mean by non-interactively?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
You should be sending your outputs to STDOUT/STDERR or some other filehandle as opposed to STDIN.
 
maybe he wants to use command line arguments?

perl programname.pl foo bar





------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Hi

Maybe this ?
Code:
#!/usr/bin/perl
open C,"|[green][i]program_to_run_non_interactively[/i][/green]";
print C "[green][i]data which should be keyed in[/i][/green]";
close C;

Feherke.
 
.

KevinADC, yes, ideally I'd have preferred to use command line arguments and then execute via e.g. a 'system' call. However, the programme that I'd like to run "non-interactively", has already been conveniently provided as a binary. In principle, I could modify the source and then re-compile it myself, but I was confident that you guys would have a more elegant solution using perl :p

brigmar, yes, of course I should've realised that STDIN would be 'reserved' for, well, standard input! Which leads on to...

feherke, yes, that's precisely what I wanted, THANKS!

MillerH, feherke's answer worked for me, but thanks anyway :)
.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top