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

Processes & Process Start Info arguments....

P: n/a
I'm using a ProcessStartInfo object to provide command line information
to a process for execution as follows:

Dim PSI as new ProcessStartInfo
PSI.Filename MyApp.exe
PSI.Arguments -blah -blah
Dim MyProcess as new Process
MyProcess.StartInfo=PSI
MyProcess.Start

It appears that the entire command line "MyApp.exe -blah -blah" cannot
be given to the .Filename property of the ProcessStartInfo class--that
is, it *must* be broken up into Filename and Arguments properties.
However, my code is provided the command line in the form of a single
string i.e. "MyApp.exe -blah -blah". I considered writing a small parser
to break the line into it's elements, based upon first space found, but
I'm worried about things like spaces in filenames, etc. if filenames are
provided in quotes.

Is there a .net command to break a command line into it constituent
Filename & Argument elements reliably?

--
================================================== ================
Sam J. Marrocco
Sr. Visual Effects Artist/R&D
Travelling Pictures/GTN
Inferno, Flame, Maya, All that cool stuff!
"The fact that no one understands you doesn't make you an artist."
================================================== ================

Nov 20 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
* Sam Marrocco <sa*@twmi.rr.com> scripsit:
I'm using a ProcessStartInfo object to provide command line
information to a process for execution as follows:

Dim PSI as new ProcessStartInfo
PSI.Filename MyApp.exe
PSI.Arguments -blah -blah
Dim MyProcess as new Process
MyProcess.StartInfo=PSI
MyProcess.Start
The code above won't work.

\\\
Dim psi As New ProcessStartInfo()
psi.FileName = "MyApp.exe"
psi.Arduments = "-blah -blah"
Process.Start(psi)
///
It appears that the entire command line "MyApp.exe -blah -blah" cannot
be given to the .Filename property of the ProcessStartInfo class--that
is, it *must* be broken up into Filename and Arguments
properties. However, my code is provided the command line in the form
of a single string i.e. "MyApp.exe -blah -blah". I considered writing
a small parser to break the line into it's elements, based upon first
space found, but I'm worried about things like spaces in filenames,
etc. if filenames are provided in quotes.


<http://groups.google.com/groups?selm=eqPpnbQlDHA.2592%40TK2MSFTNGP10.phx.gb l>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2

P: n/a


Herfried K. Wagner [MVP] wrote:
* Sam Marrocco <sa*@twmi.rr.com> scripsit:
I'm using a ProcessStartInfo object to provide command line
information to a process for execution as follows:

Dim PSI as new ProcessStartInfo
PSI.Filename MyApp.exe
PSI.Arguments -blah -blah
Dim MyProcess as new Process
MyProcess.StartInfo=PSI
MyProcess.Start

The code above won't work.


Actually, it does work, except that I left out the quotes around the
"app.exe" and "-blah -blah" strings. My mistake.
I believe your example code you suggested is directed towards reading
args from a vb.net shell-run application. MyApp.exe (in my example) is
*not* a vb.net program, and I'm not reading args into my program from a
command line--they're provided from another source, in the form
"myapp.exe -blah -blah", and read as strings into my app, where I launch
them as processes. My problem becomes, then, separating the path/appname
from the argumetns in cases such as

myapp.exe -blah -blah
c:/mypath/myapp.exe -blah -blah
"c:/my path/my app.exe -blah -blah"
myapp -blah -blah
--
================================================== ================
Sam J. Marrocco
Sr. Visual Effects Artist/R&D
Travelling Pictures/GTN
Inferno, Flame, Maya, All that cool stuff!
"The fact that no one understands you doesn't make you an artist."
================================================== ================

Nov 20 '05 #3

P: n/a
* Sam Marrocco <sa*@twmi.rr.com> scripsit:
I'm using a ProcessStartInfo object to provide command line
information to a process for execution as follows:

Dim PSI as new ProcessStartInfo
PSI.Filename MyApp.exe
PSI.Arguments -blah -blah
Dim MyProcess as new Process
MyProcess.StartInfo=PSI
MyProcess.Start The code above won't work.


Actually, it does work, except that I left out the quotes around the
"app.exe" and "-blah -blah" strings. My mistake.


Nevertheless, 'Start' is a /class method/ of the 'Process' class, not an
instance method. The code I posted shows the preferred way.
I believe your example code you suggested is directed towards reading
args from a vb.net shell-run application. MyApp.exe (in my example) is
*not* a vb.net program, and I'm not reading args into my program from
a command line--they're provided from another source, in the form
"myapp.exe -blah -blah", and read as strings into my app, where I
launch them as processes. My problem becomes, then, separating the
path/appname from the argumetns in cases such as


Thanks for clarifying that. I don't have a quick solution for this
problem.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4

P: n/a
can't you split the string of args after the app.exe? anything after the exe should be a switch (command line arg) seperated by spaces right?

Dim s As String = "c:\program files\exe\myapp.exe /b -t"
s = Mid(s, InStr(s, ".exe", CompareMethod.Text) + 5)
Dim args() As String = s.Split(" ")
Dim i As Integer
For i = 0 To args.Length
Debug.WriteLine(args(i).ToString)
Next
Nov 20 '05 #5

P: n/a
the for statement should be.

for i = 0 to args.length -
next
Nov 20 '05 #6

P: n/a


tMan wrote:
can't you split the string of args after the app.exe? anything after the exe should be a switch (command line arg) seperated by spaces right?

Dim s As String = "c:\program files\exe\myapp.exe /b -t"
s = Mid(s, InStr(s, ".exe", CompareMethod.Text) + 5)
Dim args() As String = s.Split(" ")
Dim i As Integer
For i = 0 To args.Length
Debug.WriteLine(args(i).ToString)
Next

Yes, but I can't guarantee that the command isn't something like:

AppName -blah -blah

so I can't guarantee that it ends with ".exe"

Hence, my search for a function that can "detect" where the executable
part ends and the args begin.
--
================================================== ================
Sam J. Marrocco
Sr. Visual Effects Artist/R&D
Travelling Pictures/GTN
Inferno, Flame, Maya, All that cool stuff!
"The fact that no one understands you doesn't make you an artist."
================================================== ================

Nov 20 '05 #7

P: n/a
Yes, but I can't guarantee that the command isn't something like:

AppName -blah -blah

so I can't guarantee that it ends with ".exe"

Would it be guaranteed that the args begin with a dash? So you could get
the appname before the first dash and the args start after.
Nov 20 '05 #8

P: n/a
* "=?Utf-8?B?dE1hbg==?=" <an*******@discussions.microsoft.com> scripsit:
Dim s As String = "c:\program files\exe\myapp.exe /b -t"
s = Mid(s, InStr(s, ".exe", CompareMethod.Text) + 5)


Mhm... You can start the executable even without the ".exe" suffix.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #9

P: n/a


Herfried K. Wagner [MVP] wrote:
* "=?Utf-8?B?dE1hbg==?=" <an*******@discussions.microsoft.com> scripsit:
Dim s As String = "c:\program files\exe\myapp.exe /b -t"
s = Mid(s, InStr(s, ".exe", CompareMethod.Text) + 5)

Mhm... You can start the executable even without the ".exe" suffix.

Yes, applications may have ".exe" suffixes, or none at all. It might be
a a misnomer on my part to refer to them as "executables". Application
might serve as a better term here. It might also have another
suffix--i.e. .bat, or no suffix at all.
Arguments are also just as complex. Being setup by various application
developers, they may be of the form "/blah" or "-blah" or just plain "blah"

So far, the best method I've come up with is:
If
first character is a quotation, argument starts immediately following
the next quotation character.
Else
Everything after the first space is an argument.

--
================================================== ================
Sam J. Marrocco
Sr. Visual Effects Artist/R&D
Travelling Pictures/GTN
Inferno, Flame, Maya, All that cool stuff!
"The fact that no one understands you doesn't make you an artist."
================================================== ================

Nov 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.