Click here to Skip to main content
15,884,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need to execute the below command prompt in Visual studio 2010.

Cmd: Httputil.exe "aws s3 cp" C:\TEMP\Test1.TXT <s3 bucket="" name="">

Here HttpUtil is the Visual studio project name. I need to pass
"aws s3 cp" C:\TEMP\Test1.TXT <s3 bucket="" name=""> to .net coding and execute the command.

Please anyone help.

What I have tried:

I tried with Filestream readwrite access. It is not working. Can anyone help?

C#
args2[0] = aws args2[1] = s3 args2[2] = cp args2[3] = C:\TEMP\Test1.TXT
args2[4] = <s3 bucket="" name="">

Process objProcess = new Process();
objProcess.StartInfo.FileName = "cmd.exe";
objProcess.StartInfo.Arguments = args2[0] + " " + args2[1] + " " + args2[2] + " " + args2[3] + " " + args2[4];
objProcess.StartInfo.CreateNoWindow = false;
objProcess.Start();
objProcess.Close();

It is opening the command prompt only. Not executing and not closing.
Posted
Updated 29-Jul-21 0:09am
v3

1 solution

Have a look here:
Process.Start Method (System.Diagnostics) | Microsoft Docs[^]

For your concrete problem this will look like this.

C#
var process = new Process
{
	StartInfo = new ProcessStartInfo("Httputil.exe")
	{
		Arguments = "\"aws s3 cp\" C:\\TEMP\\Test1.TXT <s3 bucket=\"\" name=\"\""
	}
};

process.Start();

Why do you call Close immediately after Start?
 
Share this answer
 
v3
Comments
Member 10556393 29-Jul-21 4:58am    
Hi,
I am not able to understand your answer. Can you explain please?
TheRealSteveJudge 29-Jul-21 5:07am    
This is a link to the original Microsoft documentation.
There are also lots of examples how to start a process.
Especially
https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.start?view=net-5.0#System_Diagnostics_Process_Start_System_Diagnostics_ProcessStartInfo_
might be interesting for you.
Just search for OpenWithStartInfo()

Member 10556393 29-Jul-21 5:21am    
Hi,
Thanks for your response.
But it is not working. The command prompt will open and the parameters i passed but it is not showing and command prompt not closing.
TheRealSteveJudge 29-Jul-21 5:39am    
Not working is the most useless description available on earth.
Show us your source code, maybe we can see what is wrong.
Member 10556393 29-Jul-21 6:05am    
args2[0] = aws args2[1] = s3 args2[2] = cp args2[3] = C:\TEMP\Test1.TXT
args2[4] = <s3 bucket="" name="">

Process objProcess = new Process();
objProcess.StartInfo.FileName = "cmd.exe";
objProcess.StartInfo.Arguments = args2[0] + " " + args2[1] + " " + args2[2] + " " + args2[3] + " " + args2[4];
objProcess.StartInfo.CreateNoWindow = false;
objProcess.Start();
objProcess.Close();

It is opening the command prompt only. Not executing and not closing.

This is my code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900