473,785 Members | 2,440 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sending StandardInput.W riteLine to a C++ Console Application

Hello,

I have a C# app that spawns several processes each containing a console
app written by another developer in C++. The console app was written
first to be just like a console app: it starts, you type a command it
does a command and returns a message. I thought I would be able to
consume it in my C# app by using the Process.Standar dInput in
conjunction with the Process.StartIn fo.RedirectStan dardOutput. The
output works fine and I can receive messages. But for some reason the
C++ app doesn't seem to be getting the messages. Here is what my side
of the code started out as:

private void StreamInput(str ing text)
{
encoderProcess. StandardInput.W riteLine(text);
encoderProcess. StandardInput.F lush();
}

But it wasn't getting the message. I read on another post that the C++
app would be expecting ASCII instead of the .NET's default Unicode so I
rewrote it like so:

private void StreamInput(str ing text)
{
byte[] byteData = Encoding.ASCII. GetBytes(text);
char[] charData = Encoding.ASCII. GetChars(byteDa ta);
encoderProcess. StandardInput.W riteLine(charDa ta);
encoderProcess. StandardInput.F lush();
}

But it *still* doesn't seem to be getting the message. Is there
something obvious that I'm not doing correctly or does the other
developer need to dig in to his side? INO, what does it take for both
side to play well with each other?

TIA,

nautonnier

Dec 15 '06 #1
2 7670
I don't think that's the issue tbh. If you have a look here,
http://msdn2.microsoft.com/en-us/lib...dardinput.aspx
you will notice that besides using a streamwriter, they don't fiddle
with the encoding and it still works fine with sort.exe which is old as
the hills.
Do you have access to the C++ source? It might be worth paring down one
of the app's and have it just write what ever it gets on stdin to a
file.
Another test you can do is to pipe output from your app into the other
app which you could do with a little test harness app. Pick one message
you would want to send, write a console app that simply does

Console.WriteLi ne("message");

then run the app from a dos box as dotnettestapp.e xe | cppApp.exe and
see what happens.
nautonnier wrote:
Hello,

I have a C# app that spawns several processes each containing a console
app written by another developer in C++. The console app was written
first to be just like a console app: it starts, you type a command it
does a command and returns a message. I thought I would be able to
consume it in my C# app by using the Process.Standar dInput in
conjunction with the Process.StartIn fo.RedirectStan dardOutput. The
output works fine and I can receive messages. But for some reason the
C++ app doesn't seem to be getting the messages. Here is what my side
of the code started out as:

private void StreamInput(str ing text)
{
encoderProcess. StandardInput.W riteLine(text);
encoderProcess. StandardInput.F lush();
}

But it wasn't getting the message. I read on another post that the C++
app would be expecting ASCII instead of the .NET's default Unicode so I
rewrote it like so:

private void StreamInput(str ing text)
{
byte[] byteData = Encoding.ASCII. GetBytes(text);
char[] charData = Encoding.ASCII. GetChars(byteDa ta);
encoderProcess. StandardInput.W riteLine(charDa ta);
encoderProcess. StandardInput.F lush();
}

But it *still* doesn't seem to be getting the message. Is there
something obvious that I'm not doing correctly or does the other
developer need to dig in to his side? INO, what does it take for both
side to play well with each other?

TIA,

nautonnier
Dec 15 '06 #2
Thanks DevX. You were right. I don't think it was the way I was sending
the message. I think it was more to with the way the c++ program was
accepting the standard stream. I made a test app in c++ and I was able
to send stuff.

However, now I'm having another (much less important) issue in my c++
test app. It sends messages saying "working" via cout every second
(after a thread Sleep command) while another thread is waiting on the
cin. For the c# side, I have a test harness using the RedirectConsole
app that's out there (basically a window with a textbox for sending
commands and a textbox for receiving messages over the standardouput
thread). It's pretty well multithreaded but I never get the "working"
messages. Any ideas?

tia,

nautonnier

DeveloperX wrote:
I don't think that's the issue tbh. If you have a look here,
http://msdn2.microsoft.com/en-us/lib...dardinput.aspx
you will notice that besides using a streamwriter, they don't fiddle
with the encoding and it still works fine with sort.exe which is old as
the hills.
Do you have access to the C++ source? It might be worth paring down one
of the app's and have it just write what ever it gets on stdin to a
file.
Another test you can do is to pipe output from your app into the other
app which you could do with a little test harness app. Pick one message
you would want to send, write a console app that simply does

Console.WriteLi ne("message");

then run the app from a dos box as dotnettestapp.e xe | cppApp.exe and
see what happens.
nautonnier wrote:
Hello,

I have a C# app that spawns several processes each containing a console
app written by another developer in C++. The console app was written
first to be just like a console app: it starts, you type a command it
does a command and returns a message. I thought I would be able to
consume it in my C# app by using the Process.Standar dInput in
conjunction with the Process.StartIn fo.RedirectStan dardOutput. The
output works fine and I can receive messages. But for some reason the
C++ app doesn't seem to be getting the messages. Here is what my side
of the code started out as:

private void StreamInput(str ing text)
{
encoderProcess. StandardInput.W riteLine(text);
encoderProcess. StandardInput.F lush();
}

But it wasn't getting the message. I read on another post that the C++
app would be expecting ASCII instead of the .NET's default Unicode so I
rewrote it like so:

private void StreamInput(str ing text)
{
byte[] byteData = Encoding.ASCII. GetBytes(text);
char[] charData = Encoding.ASCII. GetChars(byteDa ta);
encoderProcess. StandardInput.W riteLine(charDa ta);
encoderProcess. StandardInput.F lush();
}

But it *still* doesn't seem to be getting the message. Is there
something obvious that I'm not doing correctly or does the other
developer need to dig in to his side? INO, what does it take for both
side to play well with each other?

TIA,

nautonnier
Dec 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3797
by: Daniel | last post by:
after opening socket, sending data then closing socket 3000 times i get "Only one usage of each socket address" what am i doing wrong? is there some thing else i need to do to free up the socket after i send data into it? I simply want to open socket, send data, close socket and have the server just handle one client thread to recieve connection, recieve data, and close socket
3
9027
by: Wayne | last post by:
I have a console application (ssh2.exe) that requires keystrokes to be sent to it after activating. I have worked that it needs to be started in it own thread, but capturing the process and sending the keystrokes escapes me at the moment. Is there any material online that describes the process of sending keystrokes to a console app?
1
1843
by: Henk | last post by:
Hi, I have a problem with sending a file. I have a client application that connects to a server and sends the string "data". Then it sends a file. If the server receives "data", the method getCsv() is started (this receives the file) The file however isn't received completely (most of the time) this is my servercode:
0
2028
by: federico | last post by:
Hello, how can I make a program respond to another program's input request? For example, this code: Process.Start("unrar.exe", "e D:\temp\key.rar D:temp2") SendKeys.SendWait("test~") will successfully start a program that prompts for a password, and then submit the password via SendKeys. SendKeys will work with both console and windows prompts. However, the program only works when is executed by
4
2246
by: Robert McNally | last post by:
Hello, I'm currently learning c# and have been trying to write a simple program with sockets. The problem is i'm trying to send an email with an attachment, (which is the program itself) by using base64. When i run it it sends the email ok, but and attchment doesn't work i get an error when i run it. The attchment seems to be bigger (20k) then the orginal (16k) i've included the source which i have been using. Can someone tell me what...
1
2917
by: noel.phillips | last post by:
Hi, I have two threads in my application, one that decodes audio to a stream and one that encodes a stream to a file. If I run them as two seperate processes I can pipe the output from one to the input of the other - and all is well. The writes to standard output are obviously synchronous, so the decoding occurs at the rate at which the encoder can process...
3
4314
by: BuddyWork | last post by:
Hello, Could someone please explain why the Socket.Send is slow to send to the same process it sending from. Eg. Process1 calls Socket.Send which sends to the same IP address and port, the receiver is running within Process1. If I move the receiver into Process2 then its fast. Please can someone explain.
0
3168
by: Buddy Home | last post by:
There is two examples of code. Example 1. Send and Receive within the same process. Put this code in a console app called SendAndReceive and run the code. using System; using System.Collections.Generic; using System.Net; using System.Net.Sockets; using System.Runtime.Serialization.Formatters.Binary;
1
2492
by: Dv | last post by:
When our application is launched from Dos console, we need to print some message to the console. I attached our application to the console using AttachConsole(ATTACH_PARENT_PROCESS), and then call Console.WriteLine(...) to print some messages there. Everything works fine, except that after the message has been printed, it'll require user to press any key exit from there. So, I'd like to insert a key stroke to the StandardInput...
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10357
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
10162
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
9959
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
7509
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
6744
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
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
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.