473,787 Members | 2,938 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# console program output problem

2 New Member
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.WriteLi ne("");) instead? Or is there another approach?

Thanks for all contributions,

John M.
Nov 26 '07 #1
4 2520
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
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 Recognized Expert Expert
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.WriteL ine() ) and see if it picks it up?
Nov 26 '07 #3
JohnMoulding
2 New Member
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.Diagnost ics.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 Recognized Expert Expert
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
5387
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,...
4
8741
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. The obvious way to do this is by using the static Console type properties, In and Out. When trying to debug the app in the IDE however, this doesn't appear to work. I've edited the project properties and added the necessary text to the "command...
2
6204
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 (its name i cannot recall now...) where I designed the "screen" using this "program" and then saved it into an ASCII file. (thus, using 'extended' ASCII's like Lines, Corners, etc. and making screens look nicer and more professional). Then reading a...
5
11258
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 to avoid the overhead of writing to the console if it is not visible, eg I am running inside a WinForm application. thanks
1
4807
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 single-pane form GUI. I've got some stdout print statements in the code ... but I cannot find where in the world the output text is appearing. For printing I tried both: printf ("Hello world\n"); and Console::Write ("Hello World\n");
2
1445
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 I've done so with the attached code. The problem is, redirecting its output slows down the code severely. The code that starts the process is launched on its own thread, so it doesnt completely stop the interface, but the time the model takes...
3
1730
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 couldn't replicate these problems on the developer machines. And then we eventually worked out that on the dev machines Console output was going to a window, and on the test machines it was going....nowhere.
4
1547
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
2972
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 here it goes: - I am using a C library called SYMPHONY, which I compiled myself. When using that
0
10363
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, 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...
0
10172
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9964
tracyyun
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...
1
7517
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
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();...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
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
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
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...

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.