Dealing With Spaces in Commandline Runner Arguments
For the life of me I can't seem to figure this out.
I want to pass through some strings with spaces in them as commandline arguments to a C# app that takes them and parses them etc, but they always get broken up at the spaces no matter how many quotes I use.
For example:
// %system.testvar% = foo bar baz
RunCommand.exe "%system.testvar%"
passes in foo, bar and baz as three separate arguments event though I really want it as one long string.
Anyone know how to do this?
Cheers
Dave
Please sign in to leave a comment.
Hi Dave
I think this is the issue described in TW-11848.
You can use Run as custom script option as workaround.
Michael
Dave,
What TeamCity version are you running?
Did you try using something like:
Command executalue: RunCommand.exe
Command parameters: "%system.testvar%"
?
Thanks for the replies, but neither of the solutions work for me.
I did find a solution that worked, using triple quotes. """%system.testvar%"""
This is terrible.
I'm using TeamCity Professional 6.5 (build 17795)
Dave,
1) "Custom script" option runs your command as a script and hence treats quotes the same way as OS does. Why didn't it work in your particular case?
2) Command executalue: RunCommand.exe
Command parameters: "%system.testvar%"
Works fine with your example in TeamCity 6.5.
As a test in my RunCommand.exe (C#), I have:
static int Main(string[] args)
{
foreach (string arg in args)
{
Console.WriteLine("arg: {0}", arg);
}
}
So if I try in Custom Script:
RunCommand.exe foo "bar baz"
the output is
arg: foo
arg: bar
arg: baz
If I pass that same commandline into a cmd window I get:
arg: foo
arg: bar baz
It doesn't appear to matter if I use "%system.testvar%" or just any string with quotes.
Dave,
I've tried ro reproduce your problem with exactly the same TeamCity build, C# executable and parameters. But everything works fine.
Could you please attach the build log for the build where you get the described behaviour.
Could you please also check COMSPEC environment variable value on the agent where you observe the behaviour.