0

I want to execute a cmd command in C#. Below command AAA is working in Windows 10 cmd. The below code's string AAA part is not the correct format in C#. How can I change this cmd command into correct C# string format?

System.Diagnostics.Process process = new System.Diagnostics.Process();
            process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            process.StartInfo.FileName = "cmd.exe";
            string AAA= "curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "@xxx.json" "https://some.org/api/oauth/token"";
            process.StartInfo.Arguments = AAA;
ice7101
  • 69
  • 5

3 Answers3

2

You can use the escape using backslash \ before quote char ". Use the below code.

string AAA = "curl -X POST --header \"Content-Type: application/json\" --header \"Accept: application/json\" -d \"@xxx.json\" \"https://some.org/api/oauth/token\"";

Check the fiddle - https://dotnetfiddle.net/Kfz4ca

user1672994
  • 10,509
  • 1
  • 19
  • 32
  • See [MSDN](https://learn.microsoft.com/en-us/cpp/c-language/escape-sequences?view=msvc-160) for more information about escape characters – Franck Jan 06 '21 at 13:44
1

put @ in front of the string and use double qoutes.

string AAA = @"curl -X POST --header ""Content-Type: application/json"" --header ""Accept: application/json"" -d ""@xxx.json"" ""https://some.org/api/oauth/token""";
Rumplin
  • 2,703
  • 21
  • 45
1
string AAA = @"curl -X POST --header ""Content - Type: application / json""--header ""Accept: application / json"" - d ""@xxx.json"" ""https://some.org/api/oauth/token""";
serge.karalenka
  • 980
  • 1
  • 15
  • 29