I'm calling a c++ project from c# , the process is like this , i enter some numbers in a textbox and when i push a button it calls a c++.exe program and run it with the numbers i've inserted in texbox ,after this return the result in another textbox.
The problem is that i don't know how to modify in cpp I/O code to read from textbox,that's all i need .

How are you calling the C++ program? Is it C++/CLI and a .NET assembly or are you using COM? Or are you just calling a program that happens to be written in C++?

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;

namespace ProjectsManager
{
    public partial class MainForm : Form
    {
        const string exePath = "test-min.exe";


        public MainForm()
        {

            InitializeComponent();


        }

        void Button1Click(object sender, EventArgs e)
        {
            Process p = new Process();
            ProcessStartInfo pinfo = new ProcessStartInfo(exePath, textBox1.Text);

            pinfo.CreateNoWindow = true;
            pinfo.UseShellExecute = false;

            pinfo.RedirectStandardOutput = true;
            p.StartInfo = pinfo;
            p.Start();

            p.WaitForExit(3000);

            if ( !p.HasExited)
            {
                textBox2.Text = "error";
                p.Close();
            }
            else
            {
                textBox2.Text = p.StandardOutput.ReadToEnd();   
            }


        }

        private void MainForm_Load(object sender, EventArgs e)
        {

        }
    }
}


This is how i call it and in c++ i used  cin/cout in my programs but i know that here i need to change
something...

I moved this thread to C# because the fact that the process you're running is written in C++ is completely irrelevant to the question. I'm not familiar with ProcessStartInfo.RedirectStandardOutput, so I'll defer to others on whether you're using it correctly.

Well as far as i know this works fine , my problem is I/O in c++ ,that test-min.exe is a c++ file

If you can run the C++ program and see output in the command prompt, it's working and the problem is in C#.

yes , when i run the cpp.exe file it's ok , it work's in console ... well if anybody can help , please respond :) this is the c++ file that i call.It's just a simple example

#include <iostream>
#include<cstdlib>
int main() {
    int a=0;
    char b;
    std::cin>>b;

    a=atoi(&b);
std::cout << a;
return 0;
}

I don't know C#, probably should stop right there but would this work better?

const string exePath = "test-min.exe";

instead:

string exePath = "test-min.exe "+textBox1.text; or "test-min.exe "+formatnums(textBox1.text);

pinfo = procressStartInfo(exePath);

I'm assuming youre running it on the command like as such:">test-min.exe 1 2 3

ProcessStartInfo probably can't find the executable. I would suggest that you put the full path name to the executable in your exePath variable.

const string exePath = "test-min.exe";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.