By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,468 Members | 1,474 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,468 IT Pros & Developers. It's quick & easy.

C# and Process class

P: n/a
I'm trying to start a process, notepad, where I want write in some text before Notepad comes up on the screen
Obviously I don't understand how to do it
My code is
ProcessStartInfo startInfo = new ProcessStartInfo("Notepad.exe")
startInfo.WindowStyle = ProcessWindowStyle.Minimized
startInfo.UseShellExecute = false
startInfo.RedirectStandardInput = true
StreamWriter npin
Process p = new Process()
p.StartInfo = startInfo
npin = p.StandardInput
npin.WriteLine("Hej och hopp!")
p.Start()

When I run it I get the exception below! Is this a bug
An unhandled exception of type 'System.InvalidOperationException' occurred in system.dl
Additional information: StandardIn has not been redirected

Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"Folke" <fo*********@se.unisys.com> wrote in message
news:72**********************************@microsof t.com...
I'm trying to start a process, notepad, where I want write in some text before Notepad comes up on the screen. Obviously I don't understand how to do it.
My code is:
ProcessStartInfo startInfo = new ProcessStartInfo("Notepad.exe");
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardInput = true;
StreamWriter npin;
Process p = new Process();
p.StartInfo = startInfo;
npin = p.StandardInput;
npin.WriteLine("Hej och hopp!");
p.Start();
When I run it I get the exception below! Is this a bug?

An unhandled exception of type 'System.InvalidOperationException' occurred in system.dll Additional information: StandardIn has not been redirected.


Why don't you create a file named 'whatever.txt' and then fill with your
text - then simply call the file created from the Process class? - Does this
help?
JJ
Nov 15 '05 #2

P: n/a
"Folke" <fo*********@se.unisys.com> wrote:
I'm trying to start a process, notepad, where
I want write in some text before Notepad
comes up on the screen.
Obviously I don't understand how to do it.
[...]
startInfo.RedirectStandardInput = true;


You can't redirect standard input to a Windows application, only to a
console window. Perhaps you could use SendKeys instead.

P.

--
www.CL4.org
Nov 15 '05 #3

P: n/a
why not create the file on disk 1st then use the ProcessStartInfo
constructor that takes arguments.

ProcessStartInfo("Notepad.exe", "someFile.txt");

It's not elegant but it should do the trick.

Vince
"Paul E Collins" <fi******************@CL4.org> wrote in message news:<c0**********@sparta.btinternet.com>...
"Folke" <fo*********@se.unisys.com> wrote:
I'm trying to start a process, notepad, where
I want write in some text before Notepad
comes up on the screen.
Obviously I don't understand how to do it.
[...]
startInfo.RedirectStandardInput = true;


You can't redirect standard input to a Windows application, only to a
console window. Perhaps you could use SendKeys instead.

P.

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.