473,513 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# and Process class

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
3 7325

"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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2584
by: Peter Åstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
77
4505
by: Charles Law | last post by:
Hi guys I have a time critical process, running on a worker thread. By "time critical", I mean that certain parts of the process must be completed in a specific time frame. The time when the process starts is not especially important, but it must be complete within a small number of seconds. The operations I am performing do not take a...
4
8067
by: GRABLER Georg | last post by:
Hello everyone. A not too long time ago, i wrote a Post about "Reading process memory". Now, i got a good answer, about using the "marshal" class. I read over the class quickly, but i could not find a solution to write anothers process memory. As it was done in C++ (WinAPI)
10
14399
by: Sorin Dolha [MCSD .NET] | last post by:
I would like to start a process from C# code as another user. The C# code is executed as the ASPNET user because it relies in a Web Page class, and I would like that the process will run as another user to gain the required rights for execution (the external process needs to create a mailbox in Exchange, so it needs to be run as an Exchange Full...
12
2350
by: Raymond Lewallen | last post by:
How to wait for a process to stop completion is my goal. Obviously, the looping while waiting for the HasExited property is not a solution.. but thats the best I can come up off the top of my head. Natuarally it will not work. I expect it to use up all resources looping, which will not allow the process to complete. The process takes about...
9
21587
by: DraguVaso | last post by:
Hi, I want my application to bring another application to the Front. I thought best way to do this was by the Process-model: Dim c As Process = Process.GetCurrentProcess() Dim p As Process For Each p In Process.GetProcessesByName("EXTRA") If Left(p.MainWindowTitle, 4) = "Appl" Then 'Here I should be able to Bring the Process to the...
3
1262
by: Nikolay Petrov | last post by:
I have a class which starts a process and redirects it's output and input. My class have a method which starts the process and another which stops it. How can I check if the process have been already started, so I don't try to start it again, and how to check if the process is not running so i don't try to stop again? code: Public Class...
3
4265
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
3138
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;
5
1797
by: ags5406 | last post by:
I've a Windows Service that keeps a particular executable running. If the executable fails for whatever reason, the Service restarts it. Right now I'm using a loop to check if the process is running. I started with an infinite loop that ate up all of my resources, but then added a 2 second pause after every check, which seems to have mostly...
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7397
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. ...
0
7565
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...
1
7128
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5704
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5103
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...
0
4759
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...
0
3255
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.