I am writing a small console application that runs fine unless I am re-
directing the output to a file (i.e. c:\ app.exe >>output.txt) . I
have determined that the issue is caused by the Console.Clear()
function. When piping to a file, the console.clear causes the
following error:
Unhandled Exception: System.IO.IOException: The handle is invalid.
at System.IO.IO__Error.WinIOError(Int32 errorCode, String
maybeFullPath)
at System.Console.Clear()
....
Is there any way to determine where my output is being directed so
that I can skip over the Console.Clear command if I am re-directing
stdOut?
The other side of the error is with input. I prompt the user at one or
two points but if the output is re-directed, I would like to simply
skip the prompt. Again, this would be possible if I can determine
where standard output is going.
Thanks!
Dinsdale 4 6243
On Feb 28, 2:51 pm, Dinsdale <russ.ha...@gmail.comwrote:
I am writing a small console application that runs fine unless I am re-
directing the output to a file (i.e. c:\ app.exe >>output.txt) . I
have determined that the issue is caused by the Console.Clear()
function. When piping to a file, the console.clear causes the
following error:
Unhandled Exception: System.IO.IOException: The handle is invalid.
at System.IO.IO__Error.WinIOError(Int32 errorCode, String
maybeFullPath)
at System.Console.Clear()
...
Is there any way to determine where my output is being directed so
that I can skip over the Console.Clear command if I am re-directing
stdOut?
The other side of the error is with input. I prompt the user at one or
two points but if the output is re-directed, I would like to simply
skip the prompt. Again, this would be possible if I can determine
where standard output is going.
Thanks!
Dinsdale
So did nobody answer this because I am stupid and totally missed
something obvious? Seriously, hints anyone???
On Feb 28, 1:51*pm, Dinsdale <russ.ha...@gmail.comwrote:
I am writing a small console application that runs fine unless I am re-
directing the output to a file (i.e. c:\ app.exe >>output.txt) . I
have determined that the issue is caused by the Console.Clear()
function. When piping to a file, the console.clear causes the
following error:
Unhandled Exception: System.IO.IOException: The handle is invalid.
at System.IO.IO__Error.WinIOError(Int32 errorCode, String
maybeFullPath)
at System.Console.Clear()
...
Is there any way to determine where my output is being directed so
that I can skip over the Console.Clear command if I am re-directing
stdOut?
The other side of the error is with input. I prompt the user at one or
two points but if the output is re-directed, I would like to simply
skip the prompt. Again, this would be possible if I can determine
where standard output is going.
Thanks!
Dinsdale
AFIK, there is no way to tell if you have been redirected. Sorry.
--
Tom Shelton
"Tom Shelton" <to*********@comcast.netwrote in message
news:2b**********************************@e39g2000 hsf.googlegroups.com...
On Feb 28, 1:51 pm, Dinsdale <russ.ha...@gmail.comwrote:
I am writing a small console application that runs fine unless I am re-
directing the output to a file (i.e. c:\ app.exe >>output.txt) . I
have determined that the issue is caused by the Console.Clear()
function. When piping to a file, the console.clear causes the
following error:
Unhandled Exception: System.IO.IOException: The handle is invalid.
at System.IO.IO__Error.WinIOError(Int32 errorCode, String
maybeFullPath)
at System.Console.Clear()
...
Is there any way to determine where my output is being directed so
that I can skip over the Console.Clear command if I am re-directing
stdOut?
The other side of the error is with input. I prompt the user at one or
two points but if the output is re-directed, I would like to simply
skip the prompt. Again, this would be possible if I can determine
where standard output is going.
Thanks!
Dinsdale
You can't do it directly from the framework. However, take a look at http://msdn.microsoft.com/archive/de...ui07152003.asp
for information detecting redirection. Personally, I would wrap my
Console.Clear() function inside a small sub as follows:
public Sub ClearConsole()
static failed as boolean = false
if failed then exit sub
try
system.Console.Clear()
catch
failed = true
end try
end sub
Mike.
On Mar 11, 7:26*pm, "Michael D. Ober" <obermd.@.alum.mit.edu.nospam.>
wrote:
"Tom Shelton" <tom_shel...@comcast.netwrote in message
news:2b**********************************@e39g2000 hsf.googlegroups.com...
On Feb 28, 1:51 pm, Dinsdale <russ.ha...@gmail.comwrote:
I am writing a small console application that runs fine unless I am re-
directing the output to a file (i.e. c:\ app.exe >>output.txt) . I
have determined that the issue is caused by the Console.Clear()
function. When piping to a file, the console.clear causes the
following error:
Unhandled Exception: System.IO.IOException: The handle is invalid.
at System.IO.IO__Error.WinIOError(Int32 errorCode, String
maybeFullPath)
at System.Console.Clear()
...
Is there any way to determine where my output is being directed so
that I can skip over the Console.Clear command if I am re-directing
stdOut?
The other side of the error is with input. I prompt the user at one or
two points but if the output is re-directed, I would like to simply
skip the prompt. Again, this would be possible if I can determine
where standard output is going.
Thanks!
Dinsdale
You can't do it directly from the framework. *However, take a look athttp://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnar...
Hey, Michael - good find. I wasn't aware of the PeekConsoleInput
trick... This may actually be what the OP needs, because he also
wants to not display the prompt....
--
Tom Shelton This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Doug Lowe |
last post by:
In Java 1.5, what's the easiest way to get a console java app to stop until
the user presses the Enter key?
I want to do something like this:
Scanner sc = new Scanner(System.in);
String...
|
by: Kerry Brown |
last post by:
Using Microsoft Visual C# 2005 Express
With XP Pro
Console.Clear();
used as per the the sample at
http://msdn2.microsoft.com/library/209kyy3d(en-us,vs.80).aspx
is throwing an exception :...
|
by: _R |
last post by:
I've got a few apps that were designed to be used via MSDOS window.
They make use of the old-style VC++6 Console class for doing writes,
cursor repositioning, scrolling, etc. (Unfortunate name...
|
by: Homer J. Simpson |
last post by:
Hi,
Any idea to get the -REAL- number of active users -WITHOUT- this kind of
code ?
----------------------------------------------------------------------------
---------
Sub Session_OnStart...
|
by: lambertb |
last post by:
Hi folks,
I have an extremely complicated program consisting of 2 lines of codes
:
Imports System.Text.Encoding
Module Module1
Sub Main()
Console.OutputEncoding = Unicode...
|
by: Michael D. Ober |
last post by:
Is there anyway the VB Compiler can detect if a program is a console
application? I have some libraries that need to write to the console if
the program is a console app.
Thanks,
Mike Ober.
|
by: merco |
last post by:
hi,
i'm trying to write a console application using vbnet2005. It runs ok
in a command prompt.
Now, i have to use this console application via telnet (using w2003
server as telnet server) but i...
|
by: Just Me |
last post by:
I am writing a small windows applicationa and I am writing console.writeline
data to the console window. But i wanted to clear the area before writing to
the window.
I found the console.clear...
|
by: Sheikko |
last post by:
Sincerly is a little bit complicated to explain to you what I have in
my
mind, but I will try:
Above all the problem is the type of data that I want to passe between
these two applications. The...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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:
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...
|
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,...
|
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...
|
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |