Trying to test a simple console app that reads from standard in if you pipe
input into it like:
"c:\ type config.txt | consoleinput.ex e"
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.ReadLin e()) != null )
{
al.Add(line);
}
string s = Console.ReadLin e();
if ( s == null )
Console.WriteLi ne("Input is null.");
else
Console.WriteLi ne("Input is:" + s);
}
--
William Stacey, MVP 11 20917
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.mi crosoft.com> wrote in message
news:b9******** ******@cpmsftng xa10.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.OpenSta ndardInput method to
get the standard input and set back. Like this:
Stream st=Console.Open StandardInput ();
StreamReader sr=new StreamReader(st );
Console.SetIn(s r);
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.mi crosoft.com> wrote in message
news:IW******** ******@cpmsftng xa10.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.mi crosoft.com> wrote in message
news:LZ******** *****@cpmsftngx a10.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. 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
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child
|
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 application (VB.NET) will start a process,
redirect its stdout and capture that process' output, displaying it in a
window.
I've written a component for this, and a test application for the component.
It allows me to specify a command to execute,...
|
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 console.read and console.readline but they both require an <Enter> key to be hit. Any suggestions
Thanks
-KC
|
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. To do this i have
Console.WriteLine("Hi server");
while (true)
|
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 complete project
to show what happens. If anybody has an idea of how to fix
this, please let me know.
Yes I am aware that this is all in .Net 2.
Thanks in advance.
| |
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 2.3 or 2.4 has the problem that I need to
|
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 prevent from being displayed. Is there a way to prevent the
output of x.exe from python?
|
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 convert
either way.
Here's an example of the config file:
1:6,7:1,8:9,17:15,32:10
This converts a fixed-width file to a tab-delimited where the first
|
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 Python it's easy, use the ps1 prompt.
--- begin ---
import sys
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |