Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
257 views
Welcome To Ask or Share your Answers For Others

1 Answer

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""";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...