3

I'm using a console application and C# to execute some AWS (S3) CLI commands. I thought I had it working, because most of the commands execute just fine. But the last command is sync, and it doesn't work. But I know the command itself is correct, because a copy-paste into a command line window works just fine. Below is what I have so far:

String commands = "echo echo & echo echo"; 
commands += " & aws s3 ls s3://bbbbbb";
commands += " & aws s3 sync C:\test\test2 s3://bbbbbb"; //this is the line that doesn't execute
//make this to use with a Process
ProcessStartInfo commandsToRun = new ProcessStartInfo("cmd", @"/c " + commands);
//make the Process and run it
Process process = new Process();
process.StartInfo = commandsToRun;
process.Start();

I don't have any errors or any clues as to what's going on, I just don't get output from the last command, and if I check with ls or a Cloudberry Explorer, I can see that nothing has happened. Can anybody tell me what's going on here? Thanks!

4
  • Does the working directory of the command matter? Commented Aug 14, 2014 at 18:04
  • 1
    Is just one command, or several? Do you need to insert some newlines? Commented Aug 14, 2014 at 18:05
  • The working directory shouldn't matter, since the pathnames given are absolute. Commented Aug 14, 2014 at 18:10
  • it's several, but I don't know that I need newlines. both echo commands and the ls work just fine without them. Commented Aug 14, 2014 at 18:12

1 Answer 1

4

If your example is what you really use, I would blame C# string escaping. "\t" in your path will translate as horizontal tab. Use verbatim string (like you do in the ProcessStartInfo)

commands += @" & aws s3 sync C:\test\test2 s3://bbbbbb";

Or escape the backslashes

commands += " & aws s3 sync C:\\test\\test2 s3://bbbbbb";
Sign up to request clarification or add additional context in comments.

1 Comment

Oh! I never thought about string escaping. That is what I'm really using, so the @ fixed the problem. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.