We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Console.In.ReadLine()  ...my program hangs "sometimes"

Medium Priority
1,363 Views
Last Modified: 2012-05-11
I'm messing around with making a utility and i'm trying to test some code to accept input from the console.

Here's my problem...

Console.Read()   HANGS... but only sometimes, when I PIPE text into it.
For example.....

ECHO test1,test2 | splitcmd -d "," -v 1

Returns ...   test2

However, sometimes the program hangs waiting for more input.
I can't figure out how to "break" out of the loop or stop reading if nothing is there to read.  I'm at a loss as to why it would exit normally as expected only *sometimes...running the same exact test command as shown above.  Now if I ..re-pipe it to another program it exits normally ever single time.   {straaaaange}

WHAT is the "proper" method to read from the console input when PIPE'ed information is to be read????  How can I break out of Console.Read() ??

I was reading about a "beginread" method, but I have no idea how to implement it and cannot find any documentation for using it.
input = Console.ReadLine()
                Do Until input Is Nothing


                    output = input.Split(delimiter).GetValue(valueindex).ToString
                    Console.Write(output)
                    Try
                        input = Console.ReadLine()
                    Catch ex As Exception

                    End Try


                Loop

Open in new window

Comment
Watch Question

Ron MalmsteadInformation Services Manager
CERTIFIED EXPERT

Author

Commented:
More details...

The reason I don't just readline() once then exit...is because I want to process every line until there are none...

So if the console is getting input:

test1,test2
test3,test4
test5,test6

....it returns one split calc for each line.
test2
test4
test6

Split is not the actual code i'm going to implement, but i'm just using this to test the method in general until I get the In/Out working as expected.
Ron MalmsteadInformation Services Manager
CERTIFIED EXPERT

Author

Commented:
help...
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Ron MalmsteadInformation Services Manager
CERTIFIED EXPERT

Author

Commented:
Kaugmed,

Actually no...
I was wrong...

I actually have two of these progs, and when I use them in tandem is when this happens...*sometimes*.

This is the actual test, and "replacecmd", is basically the same exact code as above, but using replace instead of split functions.

C:\>echo TEST,test2,test3,testtest,test4 | c:\replacecmd.exe -o "es" -n "TESTINGS"
| c:\splitcmd.exe -d "," -v 3

Either one of them works fine when used ONLY with echo test |  ... it's when I chain them together that i'm having this problem...*sometimes*.  The cursor just hangs after returning the value, and I have to CTRL+C to end it.  Also as I said before, if I "re-pipe" this into something else it exits normally everytime without any blocking.

I'm trying to create a utility..that really has nothing to do with the above, but I want it to accept piped information and exit as it's supposed to.

Kind of like...  dsquery dsget  utilities ...where you can chain them and pipe information from one to the other.
Ron MalmsteadInformation Services Manager
CERTIFIED EXPERT

Author

Commented:
jhshukla,

Tried it, didn't work.  Same result.
Ron MalmsteadInformation Services Manager
CERTIFIED EXPERT

Author

Commented:
...ok... I think I figured it out.

I was doing Console.Write ...instead of Console.WriteLine

I think that was holding up Console.ReadLine(), because of the lack of carriage return in Write.

I'm going to hold open this question though in case this leads to other issues.
Information Services Manager
CERTIFIED EXPERT
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Ron MalmsteadInformation Services Manager
CERTIFIED EXPERT

Author

Commented:
The solution is... there is no solution apparently.

Behaviour is by design.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.