Answered Read Command Prompt

octola

New member
Joined
Jul 2, 2020
Messages
4
Programming Experience
Beginner
Hello,
I’m writing a code with a button in Outlook. When the button is triggered, I would like to launch the Windows command prompt and retrieve what the user writes in the command prompt.

I already have this piece of code which allows to write in the command prompt:

C#:
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "cmd /k echo Enter your text";
process.StartInfo.UseShellExecute = false;
process.Start();
But I don’t know which line to write to retrieve what is then written in the command prompt. Does anyone have an idea?

Thank you in advance
 

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
814
Location
Norway
Programming Experience
10+
Why not use the InputBox function? (add reference to Microsoft.VisualBasic)
C#:
var input = Microsoft.VisualBasic.Interaction.InputBox("enter text:");
 

Dalski

Active member
Joined
Jun 3, 2020
Messages
40
Programming Experience
Beginner
John knows much more than me & obviously what's linked there is a better way, but for your curiousity to obtain in input from a user and store it as a variable:

C#:
string answer = Console.Readline()
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,140
Location
Sydney, Australia
Programming Experience
10+
Hello,
I’m writing a code with a button in Outlook. When the button is triggered, I would like to launch the Windows command prompt and retrieve what the user writes in the command prompt.

I already have this piece of code which allows to write in the command prompt:

C#:
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "cmd /k echo Enter your text";
process.StartInfo.UseShellExecute = false;
process.Start();
But I don’t know which line to write to retrieve what is then written in the command prompt. Does anyone have an idea?

Thank you in advance
If you did want to go that way, this would be the place to start:

 
Top Bottom