| Author |
Message |
< Erlang ~ How to read STDIN without prompt |
| lyntongrice |
Posted: Thu Mar 25, 2010 8:32 am |
|
|
|
Joined: 25 Mar 2010
Posts: 4
|
Hi there,
Quick one, in C I can use GETS to read STDIN, in Python I can use sys.stdin.read().
In Erlang I can see I can use io:read()...like:
read([IoDevice,] Prompt) -> Result
What I am trying to do is have Erlang read STDIN just like C or Python with no prompt...is this easy?
Thanks
Lynton |
|
|
| Back to top |
|
| bpuzon |
Posted: Thu Mar 25, 2010 12:34 pm |
|
|
|
User
Joined: 05 Aug 2009
Posts: 23
Location: Cracow, Poland
|
Code: io:read([IoDevice], ""). should work. |
_________________ Saludos,
Bartłomiej Puzoń
Erlang Solutions |
|
| Back to top |
|
| lyntongrice |
Posted: Fri Mar 26, 2010 4:03 am |
|
|
|
Joined: 25 Mar 2010
Posts: 4
|
Hi there,
Thanks for the response, much appreciated
I guess what I am trying to do is execute something like the following on my windows machine:
echo hello | erl receiver execute | result.txt
And here is the code below for "receiver.erl"
Code: -module(receiver).
-export([execute/0]).
execute() ->
Data = io:read(standard_io, ""),
io:format(Data),
io:write(standard_io, "Done").
I want to simply read STDIN and print out some value to STDOUT...which ends up in a file called "result.txt".
Also why can I not do the following?
erl receiver execute | result.txt
It says "'result.txt' is not recognized as an internal or external command..."
Any ideas? Thanks for the help
Lynton |
|
|
| Back to top |
|
| Michal Ptaszek |
Posted: Fri Mar 26, 2010 8:42 am |
|
|
|
User
Joined: 01 May 2008
Posts: 35
Location: Krakow
|
Using pipe (|) simply redirects standard I/O to the next process in line. If you would like to dump the output to the file, use redirection operator:
echo hello | erl receiver execute > result.txt
Or, if you like to save the data AND redirect it to the next process, use tee
echo hello | erl receiver execute | tee result.txt | ANOTHER_PROCESS |
|
|
| Back to top |
|
| lyntongrice |
Posted: Fri Mar 26, 2010 10:05 am |
|
|
|
Joined: 25 Mar 2010
Posts: 4
|
Hi there,
Many thanks for the feedback, much appreciated
Can you copy the code from my receiver.erl above and try get the following to work...
echo hello | erl receiver execute > result.txt
Sure, the output is sent to file "result.txt" but there is an error ;-(
Can you try it out for me?
Thanks
Lynton |
|
|
| Back to top |
|
| jwatte |
Posted: Fri Apr 09, 2010 2:10 am |
|
|
|
User
Joined: 10 Feb 2010
Posts: 34
|
| I think you'll need to copy & paste to post the error in question for anyone to help you. |
|
|
| Back to top |
|
| wuji |
Posted: Mon Sep 17, 2012 8:09 am |
|
|
|
User
Joined: 10 Aug 2012
Posts: 654
|
governor to deny in-state tuition for illegal immigrants.Democrats have said said jordan 11 concords said they plan to hold Romney to those positions, painting
as a candidate with extreme views on immigration. Romney's campaign campaign replica designer *beep* campaign stumbled last month when the Republican National Committee's director
Hispanic outreach told reporters that Romney was "still deciding what what cheap replica designer *beep* what his position on immigration is," fueling the notion that
holds few true convictions.Kevin Madden, a former Romney adviser, today today jordan 11 concords today said on MSNBC that, "there are going to be
lot more questions here, I think particularly up on Capitol Capitol [h3]cheap jordan shoes[/h3] Capitol Hill and the Congress' role in whether or not
believe that the president can go out and around Capitol Capitol replica designer *beep* Capitol Hill and around legislatures and around Congress on something |
|
|
| Back to top |
|
| dongdongwu |
Posted: Wed Sep 19, 2012 3:20 am |
|
|
|
User
Joined: 19 Sep 2012
Posts: 236
|
| Girls would refuse to even leave their replicas behind. specifically when the product beats the complete meaning of the Christian Louboutin men outlet; in conditions of good quality and detailing.If Cinderella was residing in your twenty primary century as opposed to the aged a single then there would not be any 'Happy actually after'. properly appears like girls nowadays are as well fond of the strong;Christian Louboutin Men Shoes to leave them in your center of nowhere.Christian Louboutin for men Shoes would arrive true handy being a excellent handbag using the glimpse and really feel belonging to the authentic but at a very much lesser price tag adding as very much as types picture in your process. |
|
|
| Back to top |
|
|
|