Processes & Process Start Info arguments....

S

Sam Marrocco

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."
==================================================================
 
H

Herfried K. Wagner [MVP]

* Sam Marrocco said:
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/[email protected]>
 
S

Sam Marrocco

Herfried said:
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."
==================================================================
 
H

Herfried K. Wagner [MVP]

* Sam Marrocco said:
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.
 
G

Guest

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
 
S

Sam Marrocco

tMan said:
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."
==================================================================
 
S

Slonocode

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.
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?dE1hbg==?= said:
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.
 
S

Sam Marrocco

Herfried said:
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."
==================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top