
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
730
|
Chapter 12: Filesystem I/O
Discussion
Once the input has been redirected, you can write into the standard input stream of
the process by reading the Process.StandardInput property, which returns a
StreamWriter. Once you have that, you can send things to the process via WriteLine
calls, as shown earlier.
In order to use
StandardInput, you have to specify true for the StartInfo property’s
RedirectStandardInput property. Otherwise, reading the StandardInput property
throws an exception.
When
UseShellExecute is false, you can use Process only to create executable pro-
cesses. Normally the
Process class can be used to perform operations on the file, like
printing a Microsoft Word document. Another difference when
UseShellExecute is
set to
false is that the working directory is not used to find the executable, so you
should be mindful to pass a full path or have the executable on your
PATH environ-
ment variable.
See Also
See the “Process Class,” “ProcessStartInfo Class,” “RedirectStandardInput Prop-
erty,” and “UseShellExecute Property” topics in the MSDN documentation.
12.22 Locking Subsections of a File
Problem
You need to read or write data from or to a section of a file, and you want to make
sure that no other processes or threads can access, modify, or delete the file until you
have finished ...