I'm trying to launch a command line utility from my VB.NET App, In my
function I create a process and launch the executable, and need to wait for
it to exit, so that the calling code can move the output file to the
userdata directory, if it's successful.
The problem I'm having is that on myProcess.WaitForExit() I get a
System.NullReferenceException, Object Reference not set to an instance of an
object.
Here's my function.
Private Function GenerateOutput(ByVal myDirectory As DirectoryInfo, ByVal
OptionFile As FileInfo, ByVal LicenceFile As FileInfo) As Boolean
'Spawn Process to execute util and wait for it to finish
Dim psi As New ProcessStartInfo((IO.Path.Combine((myDirectory.ToS tring),
"util.exe")), "-f " & OptionFile.Name.ToString)
psi.RedirectStandardOutput = True
psi.RedirectStandardError = True
psi.CreateNoWindow = True
psi.WorkingDirectory = myDirectory.ToString
psi.UseShellExecute = False
Dim myProcess As Process
Try
myProcess.Start(psi)
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
myProcess.WaitForExit() '**Error occurs on this line**
myProcess = Nothing
Return True
End Function 5 3501
"Kevin Hodgson" <ke***@caseware.com> wrote in message
news:ON**************@TK2MSFTNGP09.phx.gbl... I'm trying to launch a command line utility from my VB.NET App, In my function I create a process and launch the executable, and need to wait
for it to exit, so that the calling code can move the output file to the userdata directory, if it's successful.
The problem I'm having is that on myProcess.WaitForExit() I get a System.NullReferenceException, Object Reference not set to an instance of
an object.
Here's my function. Private Function GenerateOutput(ByVal myDirectory As DirectoryInfo, ByVal OptionFile As FileInfo, ByVal LicenceFile As FileInfo) As Boolean 'Spawn Process to execute util and wait for it to finish Dim psi As New
ProcessStartInfo((IO.Path.Combine((myDirectory.ToS tring), "util.exe")), "-f " & OptionFile.Name.ToString) psi.RedirectStandardOutput = True psi.RedirectStandardError = True psi.CreateNoWindow = True psi.WorkingDirectory = myDirectory.ToString psi.UseShellExecute = False Dim myProcess As Process Try myProcess.Start(psi)
here's your problem. This line should be
myProcess = Process.Start(psi)
myProcess is nothing there and you were never assigning it. Process.Start
is shared so the compiler was letting you run it on a Nothing reference.
But myProcess stayed unassigned. Some other languages won't let you invoke
a shared (static) member through a reference to an instance to avoid such
confusion.
David
Thanks, that fixed it.
"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:ei**************@TK2MSFTNGP10.phx.gbl... Try myProcess.Start(psi) here's your problem. This line should be
myProcess = Process.Start(psi)
myProcess is nothing there and you were never assigning it. Process.Start is shared so the compiler was letting you run it on a Nothing reference. But myProcess stayed unassigned. Some other languages won't let you
invoke a shared (static) member through a reference to an instance to avoid such confusion.
David
* "Kevin Hodgson" <ke***@caseware.com> scripsit: I'm trying to launch a command line utility from my VB.NET App, In my function I create a process and launch the executable, and need to wait for it to exit, so that the calling code can move the output file to the userdata directory, if it's successful.
You already got an answer to this question yesterday and confirmed that
the problem was solved...
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
No I didn't, you must be thinking of someone else.
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2l************@uni-berlin.de... * "Kevin Hodgson" <ke***@caseware.com> scripsit: I'm trying to launch a command line utility from my VB.NET App, In my function I create a process and launch the executable, and need to wait
for it to exit, so that the calling code can move the output file to the userdata directory, if it's successful.
You already got an answer to this question yesterday and confirmed that the problem was solved...
-- Herfried K. Wagner [MVP] <URL:http://dotnet.mvps.org/>
* "Kevin Hodgson" <ke***@caseware.com> scripsit: No I didn't, you must be thinking of someone else.
Sorry, I thought of someone else. When looking for the old post in OE,
I found your reply in this thread which I didn't see in gnus :-(.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Peter Steele |
last post by:
I have a Windows application written in C# that I want to return a non-zero
exit code when it it run. The problem is that as a Windows application,
there doesn't seem to be a way to control this....
|
by: jam |
last post by:
Dear All,
I have a command process running xcopy in console, and now I want to execute
the program Rsync After the files are copied...how could i do??
Process p10=new Process();...
|
by: JM |
last post by:
Hi,
I need a function for a character based program (console) that works exactly
like the INKEY$() function in (old) QBasic: Read only 1 keystroke and then
move on. Console.Read;...
|
by: Jarod_24 |
last post by:
I got a project called "Forms" that hold some forms and stuff in my
solution.
A argument at startup defines wether to use a From or Console.
My plan was to create a myConsole class that would...
|
by: Tim Werth |
last post by:
I have a .NET console application that is kicked off by a .NET Windows
service. They communicate via .NET Remoting, although there isn't much
communication between the two while the console app is...
|
by: Marco Shaw |
last post by:
C# novice...
Can I create a console application (think the Pine email reader or even
'edit' in DOS) where I can use my up/down/side arrows to move around the
app?
I'd want something with a...
|
by: Daniel Clark |
last post by:
I have a Windows command line based application that only shuts down
cleanly if it sees "CTRL-C" on the console. I need to automate the
running of this application, but still allow the user sitting...
|
by: federico |
last post by:
Hello, I am trying to setup a Visual Basic "Console" application for
searching Outlook folders. To this end I am trying to implement a Handler
for the Outlook.Application.AdvancedSearchComplete...
|
by: tombrogan3 |
last post by:
Hi, I'm writing a service which has to monitor a database looking for
new feeds (basically a few hundred thousand rows with a common id).
When it finds a new feed I can either:
1) Process it on...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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,...
|
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...
| |