4

I have some string with variable, e.g.

string path = @"C:\one\filename.exe" + arguments

arguments: "-s -c -d > "somedirectory\some file.txt""

I've problem with redirection output to "somedirectory\some file" If I put "\"" or char.ToString('"') it always interprets as \"...not alone "

How should I put this " character into arguments?

Saint
  • 5,397
  • 22
  • 63
  • 107

3 Answers3

18

You need to use \".

The debugger shows it as \", since it shows valid string literals.
However, the actual value in the string is ". (You can see this in the Text Visualizer)

In a verbatim string literal (@"..."), you need to use "" instead.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • This path is in *.bat file. So why it doesn't wokr from code, and if I run manualy this bat file it work correctly? – Saint Jul 27 '11 at 14:47
  • If I run from bat file this line it works C:\one\filename.exe" -s -c -d > "somedirectory\some file.txt" pause but in code it doeasn't – Saint Jul 27 '11 at 14:49
  • How are you running it in code? You should use `RedirectStandardOutput` instead. – SLaks Jul 27 '11 at 14:52
5
var arguments =  @"-s -c -d > ""somedirectory\some file.txt""";

or

var arguments = "-s -c -d > \"somedirectory\\some file.txt\"";
Kirill Polishchuk
  • 54,804
  • 11
  • 122
  • 125
0
string args = @"-s -c -d > ""somedirectory\some file.txt"""

try that.

for more information, http://msdn.microsoft.com/en-us/library/aa691090%28v=vs.71%29.aspx

Adriano Carneiro
  • 57,693
  • 12
  • 90
  • 123