I have a string containing a path to an executable file that also may or may not have command line arguments in it.
For example:
"C:\Foo\Bar.exe"
"C:\Foo\Bar.exe /test"
"C:\Foo\Bar.exe {0}"
"C:\Foo\Bar.exe -snafu"
I'm trying to break the string up into path part and the arguments part. The arguments part may be in pretty much any format. But the IO.Path functions assume that the string is a path without arguements. For example, if I call:
IO.Path.GetFileName(path)
It returns Bar.exe /test
, Bar.exe {0}
or Bar.exe -snafu
Windows can obviously tell the difference when I run this at a command prompt so there must be some way to leverage an existing function.
I can surround the path part of the string in quotes if I need to. But then the IO.Path
calls fail. For example:
? IO.Path.GetFileName("""C:\Windows\write.exe"" {0}")
Throws an Arguement Exception: Illegal characters in path.