473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

C# console program output problem

Hi,

I'm a newbie, so apologies for missing the obvious... and I have searched for an answer to this question, but all I get is "how to call an external program from a C# program" - which is not what I'm looking for.

I've written a C# console program that, after retrieving data from an SAP database, writes a simple (30 character) output string to a text file in a local directory. It works fine, and the fact that I can run it from the command line means it is easy to test.

We have a requirement to call my C# program from a Visual Objects program (not mine, don't know much about it). I do know that the Visual Objects program opens an Input Pipe to capture output from my C# program. So, instead of writing my result string to a text file, I simply need it to be captured by the calling program.

Do I just direct the output to the console (using Console.WriteLine("");) instead? Or is there another approach?

Thanks for all contributions,

John M.
Nov 26 '07 #1
4 2500
Shashi Sadasivan
1,435 Expert 1GB
Hi,
sounds interesting on what you have to do.
But i think that putting the output onto a screen and then capturing what happened is not fesiable.
Not would it be fesiable to load it into the buffer and and then read the buffer (because you will have mouse movements, other programs outputs, misc activities, etc)

Either you should stick with letting the external program monitor the output file being written to and read any changes made to it.

OR.... you might make a DLL or use the exe file and get an output from it (which will require a few modifications in your application)
Nov 26 '07 #2
Plater
7,872 Expert 4TB
If this program captures the pipe for your program, then it probably captures the StandardOut (and maybe StandardError too?), you could try just ouputing the text to the console (Console.WriteLine() ) and see if it picks it up?
Nov 26 '07 #3
Hi,

thank you, yes, I could try that, but it's a nightmare to test the VO program, and I don't even know if it's working properly yet. I first have to know that my program is correct.

So, I'm thinking of creating a "test harness" program, written in C#, to test my own C# program! Sounds a bit crazy, but at least I can be sure that a value is being passed back to the calling program.

I think I need to use the System.Diagnostics.Process functionality, but I'm not certain how to make the calling program wait until the called program is finished. I don't want to just put in a "wait" loop with a timeout. I want the calling program to stop processing until the called program finishes - oh yes, and returns a value (not sure how to do this either).

Any more contributions gratefully received ;-),

John M.
Nov 26 '07 #4
Plater
7,872 Expert 4TB
Well you could do checks from the command line first?
If you ran this from the command line:
Expand|Select|Wrap|Line Numbers
  1. myprogram.exe > myoutput.txt
  2.  
The output pipe of your program is re-directed to the myoutput.txt file. If that captures everything correctly I would think it would be fine?

Also, if myprogram.exe's main() function returns a "0" on good status or any other number on error (like old school program used to) then you can use:
Expand|Select|Wrap|Line Numbers
  1. ECHO %ERRORLEVEL% 
  2.  
to see the value it returned.
Nov 26 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
4
by: Bill Cohagan | last post by:
I'm writing a console app (in C#) and I want to be able to redirect the standard input/output streams when it's run at a command prompt. IOW I want to support the "<" and ">" redirection syntax....
2
by: Martín Marconcini | last post by:
Hello there, I'm writting (or trying to) a Console Application in C#. I has to be console. I remember back in the old days of Cobol (Unisys), Clipper and even Basic, I used to use a program...
5
by: Barry Mossman | last post by:
Hi, can I detect whether my class is running within the context of a Console application, vs say a WinForm's application ? also does anyone know whether the compiler or runtime is smart enough...
1
by: noleander | last post by:
Hi. I've got a C++ program written in Visual C++ 2003. The program is trivial, created with the Program-creation wizard: used the .NET "Form" template. The program has a trivial...
2
by: Dave Taylor | last post by:
I'm writing an app in VB.NET that provides a user-interface to computer simulation model that runs as a console process. I would like to have the console output redirected to my VB.NET program and...
3
by: Andrew Ducker | last post by:
We were using Console.Writeline from within our app, to do some routine debugging. And then we started having random problems when the code was run by a tester, on their own machine. We...
4
by: djc | last post by:
is this possible: lets say my output has 2 columns with headings like 'host' and 'status'. host status ------------ host1 down host2 up host3 up host4 down
27
by: CarlosMB | last post by:
Hello, I am writing code that uses a DLL which is supposed to print to console some useful information but for some reason it is not doing so. The environment is a bit complex to explain but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.