System.Diagnostics.ProcessStartInfo with string arguments

I've to pass to  a cmd file 2 arguments: the first is a number and the second is a description string containing spaces.
My code looks like this ...
Dim psi As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo
        psi.FileName = "C:\Test.cmd"
        psi.Arguments = Par_Arguments
        psi.WindowStyle = ProcessWindowStyle.Normal
        System.Diagnostics.Process.Start(psi)

Par_Arguments is the variable that contain the 2 arguments.
My trouble is what I have to do to build the second string argument with spaces.
fantamenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

petr_hlucinCommented:
Since you don't have specified the value of Par_Arguments value I think it is something like this:
Par_Arguments = "5     "

Use the following instead:
Par_Arguments = "5 \"     \""
0
StupormanCommented:
What does the assignment statement of Par_Arguments look like?
0
fantamenAuthor Commented:
The value of Par_Arguments can be for example "2 Messaggio di prova" where the first parameter is "2" and the second "Messaggio di prova".
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

StupormanCommented:
In that case, petr_hlucin's answer is what you need. it would look like this:

Par_Arguments = "2 \"Messaggio di prova\""

The reason you need this is that Windows splits your argument string by spaces, so your raw text gets passed as 4 different arguments instead of two. That means you need to surround the second argument with quotes, and the only way to do that in VB is to use the escape sequence for quotes, which is \".

Buona Fortuna, mi amici.
0
fantamenAuthor Commented:
If I write
Par_Arguments = "2 \"Messaggio di prova\""
the compiler returns end of statements expected...
0
Éric MoreauSenior .Net ConsultantCommented:
vb escape char is not \, it is "

try this:

Par_Arguments = "2 ""Messaggio di prova"""
0
StupormanCommented:
I'm sorry, I was confused with C#. To escape quotes in VB, use two in a row like this:

Par_Arguments = "2 ""Messaggio di prova"""
0
fantamenAuthor Commented:
Now code is compiled correct but I'm investigating for a bad response from .cmd file.
It run correctly only if second parameter don't contain spaces.
0
Éric MoreauSenior .Net ConsultantCommented:
I think I already had this problem. try doubling them once more:


        Par_Arguments = "2 """"Messaggio di prova"""""
0
fantamenAuthor Commented:
Using your assignment the second parameter is evalueted partially, only until "Messaggio" and the substring " di prova" is discarded.
0
Éric MoreauSenior .Net ConsultantCommented:
can you try:


        Par_Arguments = "2 " + Chr(34) + "Messaggio di prova" + Chr(34)
0
fantamenAuthor Commented:
I've tried before opening the thread in expert exchange but 2 parameter was discarded e not recognized.
0
fantamenAuthor Commented:
Good. Now probably I've found the reason: in batch file there is this line:
if "x%1"=="x" goto Missing_Severity

I've replaced with

if [%1]==[] goto Missing_Severity

... and now all works correctly.

Can you confirm my change is correct?


Thanks
0
Éric MoreauSenior .Net ConsultantCommented:
Sincerely, i can't really but since you tested it and it is working properly, you should consider it as good.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fantamenAuthor Commented:
To solve was necessary not only batch modifcations but your indications too. So thank you very match!.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.