views:

245

answers:

1

I have looked at the answers already provided, but I'm still stuck. Here is what I currently have:

 start "" "C:\Program Files (x86)\Spark\Spark.exe"
 echo Spark started

This works fine. But now I want to pass parameters to the client, which must be wrapped in quotes. I can do the following on the command line:

 "C:\Program Files (x86)\Spark\Spark.exe" "user=%USERNAME%&server=example.org"

And it starts up with the user and server fields filled in.

But when I try to edit the batch script to add those quote-wrapped parameters, I get a variety of errors depending on how I try to add double-quotes and where, etc.

So how would I add a quote-wrapped parameter to the start line?

Update:

I accidentally got it to work, but haven't been able to reproduce it. But it didn't work exactly right. The user name was still blank, but the server was filled in. I forgot to mention that I am using an environment variable for the user name: %USERNAME%

So it might be my problem is that I can't escape quotes and use environment variables?

Final Answer:

It turns out that part of the problem was that I was using the wrong parameter, but originally I had been using the right one, so I didn't notice. From the command line, I should have:

 "C:\Program Files (x86)\Spark\Spark.exe" "username=%USERNAME%&server=example.org"

and so from the batch file, the following works:

 start "" "C:\Program Files (x86)\Spark\Spark.exe" "username=%USERNAME%&server=example.org"
 echo Spark started

Much thanks and points to dcp for getting me to the right answer.

+1  A: 

Did you try this?

"C:\Program Files (x86)\Spark\Spark.exe" "\"user=foo&server=example.org\""

This worked when I tried a simple command line test and c++ program (I could see the quotes when I printed the argv[1] argument).

UPDATE: If %USERNAME% has spaces in it, then you need to quote it like this (see below). I think you can remove the other quotes.

"C:\Program Files (x86)\Spark\Spark.exe" user="%USERNAME%"&server=example.org
dcp
No, no luck. It is a batch script with a simple `.bat` extension, if that helps.
Anthony
I created a program called temp.cpp and when I printed out the argument it has the double quotes around it. Do you have the source for the Spark.exe program? Can you step through it in the debugger and verify that the quotes are/aren't there? This should work as far as I can tell.
dcp
I don't think the problem is with Spark. I can write out the command with the parameters from the command line and it works fine. But when I try to put it into a batch script, it's not working. The problem is a combination, I think, of the double quotes, the environment variable, and trying to start it with parameters. I'm feeling more clueless and frustrated with every attempt, but the problem is definitely not with spark.
Anthony
See my latest update. Give that a try and let us know how you make out.
dcp
Anthony