Trying to test a simple console app that reads from standard in if you pipe
input into it like:
"c:\ type config.txt | consoleinput.exe"
Seem to run into an issue. It seems like if you use a pipe, you can read
all the input lines fine until eof. However, if you need to then prompt for
input, the pipe is still hooked up so Read or ReadLine returns with -1 or
null after that point. So you can't prompt for "Hit a key to continue",
etc. I am guessing I need to somehow disconnect the pipe from stdin or
"refresh" the stdin stream so it again starts waiting for normal console
input. Have tried various things, but can't seem to again get normal Read
or Readline behavior. Any thoughts? TIA
== Test Method called from Main ===
static void ReadStdIn()
{
string line;
ArrayList al = new ArrayList(200);
while ( (line = Console.ReadLine()) != null )
{
al.Add(line);
}
string s = Console.ReadLine();
if ( s == null )
Console.WriteLine("Input is null.");
else
Console.WriteLine("Input is:" + s);
}
--
William Stacey, MVP 11 20846
Hi William,
I have viewed your post, I will spend some time on it, I will reply to you
ASAP.
Thanks for your understanding.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Thanks Jeffrey. This may be normal behavior. However, things like "less"
seem to do just this after draining the pipe they prompt to hit any key
after a screenfull. They probably are doing some other trick like a new
process or something. Your help is appreciated. Cheers!
--
William Stacey, MVP
""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:b9**************@cpmsftngxa10.phx.gbl... Hi William,
I have viewed your post, I will spend some time on it, I will reply to you ASAP.
Thanks for your understanding.
Best regards, Jeffrey Tan Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights.
Hi William,
So far as I think, we should can use Console.OpenStandardInput method to
get the standard input and set back. Like this:
Stream st=Console.OpenStandardInput ();
StreamReader sr=new StreamReader(st);
Console.SetIn(sr);
But, I can not get this work as expected. Anyway, I will still spend some
time on it. Please wait a little more time.
Thanks for your understanding.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Hi William,
Sorry for letting you wait for so long time.
I am current consulting internally, I have received some useful feedback
for this issue. I am still asked for further confirmation. Please wait a
little more time.
Thanks for your understanding.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Thanks
--
William Stacey, MVP
""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:IW**************@cpmsftngxa10.phx.gbl... Hi William,
Sorry for letting you wait for so long time.
I am current consulting internally, I have received some useful feedback for this issue. I am still asked for further confirmation. Please wait a little more time.
Thanks for your understanding.
Best regards, Jeffrey Tan Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights.
Hi William,
Sorry for letting you wait for so long time.
It seems that CreateFile Win32 API can be used to create the console input
stream through specify "CONIN$" as the lpFileName parameter. For more
information, please refer to "Consoles" section in CreateFile API in MSDN.
You may try to P/invoke it and then use FileStream class to wrap it.
=============================
Please apply my suggestion above and let me know if it helps resolve your
problem.
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Hi William,
Have you tried my suggestion? Do you still have any concern on this issue?
Please feel free to feedback. Thanks
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Hi William,
Have you tried my suggestion? Do you still have any concern on this issue?
Please feel free to feedback. Thanks
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Sorry for delay. Thanks Jeffrey, that helps. Cheers!
--
William Stacey, MVP
""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:LZ*************@cpmsftngxa10.phx.gbl... Hi William,
Have you tried my suggestion? Do you still have any concern on this
issue? Please feel free to feedback. Thanks
Best regards, Jeffrey Tan Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights.
Sorry for delay. Thanks Jeffrey, that helps. Cheers!
--
William Stacey, MVP
""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:LZ*************@cpmsftngxa10.phx.gbl... Hi William,
Have you tried my suggestion? Do you still have any concern on this
issue? Please feel free to feedback. Thanks
Best regards, Jeffrey Tan Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights.
Hi William,
I am glad I can help you. You are welcome!!
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bernhard Kuemel |
last post by:
Hi!
I want to read/write commands and program input to/from /bin/bash
several times before I close the stdin pipe. However, reading
from cat hangs unless I first close the stdin pipe.
<?php...
|
by: Oz |
last post by:
This is long. Bear with me, as I will really go through all the convoluted
stuff that shows there is a problem with streams (at least when used to
redirect stdout).
The basic idea is that my...
|
by: Kerwin Cabrera |
last post by:
I am writing a console application and I would like to put a "Press any key..." message once the program is done executing. Currently, when it executes it returns to the prompt. I have tried...
|
by: ~toki |
last post by:
I have a full work app (server and client) that talk between two executables
trought Console.WriteLine(); & Console.ReadLine();
I have the source code of the server.
I need to make the client....
|
by: Publicjoe |
last post by:
I am working on a little app which uses colour in the console window. I have
created a class to extend the console functionality but the ClearScreen
method does not work correctly. I am enclosing a...
|
by: Christoph Haas |
last post by:
Hi...
I encountered a problem that - according to my google search - other
people have found, too. Example code:
import sys
for line in sys.stdin:
print line
Running this code in Python...
|
by: Kkaa |
last post by:
I'm using the os.system command in a python script on Windows to run a
batch file like this:
os.system('x.exe')
The third-party program x.exe outputs some text to the console that I
want to...
|
by: Shawn Milochik |
last post by:
I wrote a script which will convert a tab-delimited file to a
fixed-width file, or a fixed-width file into a tab-delimited. It reads
a config file which defines the field lengths, and uses it to...
|
by: Gabriel Genellina |
last post by:
En Thu, 25 Sep 2008 09:49:31 -0300, Almar Klein <almar.klein@gmail.com>
escribió:
Use subprocess.PIPE
Usually the tricky part is to figure out exactly whether there is more
input or not. With...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| | |