0

I am writing a launcher in C# that processes user input and I would like its corresponding output string to be piped into an external program. The external program is a precompiled C# executable that is end-of-life, so I cannot easily modify it.

I can easily launch the desired program using ExternalProcess, but do not see any means for sending data over. My desired function calls go something like:

string myString = "string to pass over"
Clipboard.SetText(myString);

Process ExternalProcess = new Process();
ExternalProcess.StartInfo.FileName = "Notepad.exe";
ExternalProcess.Start();

// some kind of paste command here...
// ExternalProcess.magicpaste(myString);

ExternalProcess.WaitForExit();

Is there a better way to go about this? I realize the purported security implication in piping text this way, but I need to create a simple launcher program to support a legacy project.

sam
  • 488
  • 8
  • 21
  • can you give more details on what the legacy program actually does.. as well as an example of the type of text that's being passed over.. it's a bit vague in regards to what you have posted so once Notepad.exe has started.. then in your case what do you expect to do once you close the file.. – MethodMan Nov 03 '15 at 19:07
  • @MethodMan I quite literally just need to pass some plain text, hence the Notepad example. Basically I just need to autofill field in a form that is inside another program. – sam Nov 03 '15 at 19:10
  • take a look here http://stackoverflow.com/questions/16057063/how-to-pass-parameters-to-another-process-in-c-sharp and if that doesn't help do a simple google search search on the following `C# passing params to another process` – MethodMan Nov 03 '15 at 19:11
  • @MethodMan I am familiar with command line params, and would go that route if I could. Unfortunately that would be changing the code of the legacy program I am trying to make the launcher for. i.e. it is not expecting any params – sam Nov 03 '15 at 19:14

1 Answers1

3

Given your answer in the comments that you need to put some text in a field, I'm afraid you're going to have to get your hands dirty.

That text box (I assume that's what it is) in this legacy application, will be a window. And you're going to have to find it, and send it a message using Platform-Invoke. This question should get you started.

If said control has a name, you can find it using Spy++.

Community
  • 1
  • 1
Moo-Juice
  • 38,257
  • 10
  • 78
  • 128