Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

running command C# Mono using pipe

Writer Andrew Mclaughlin

I'm creating an application running on a debian OS using C# and Mono. My aim is to unpack an imagefile and transfer it to a target folder on a different harddrive. I'm trying to pass the command

"gunzip -c imagefile.img.gz | dd of=/dev/sda" 

to the OS in order to restore an imagefile to the local hard drive. I did some research and found here that it probably have to redirect the standardinput/output. The problem in my case is that the ouput is somewhere between 1-60 gigabyte and the answer suggests to read it into memory.

Up to now I ceated this method:

public bool RecoverImageDD(string imageFile, string targetDiskNr)
{ string commandToExecute=""; string arguments=""; string imgExtension = Path.GetExtension(imageFile).ToLower(); if (imgExtension == ".gz") { commandToExecute = $"gunzip"; string par1 = "-c"; string par3 = "| dd"; string par4 = $"if={imageFile}"; string par5 = $"of={targetDiskNr}"; arguments = string.Join(" ", par1, imageFile, par3, par4, par5); // gunzip -c image.img.gz | dd of=/dev/sda } Process proc = new Process { StartInfo = new ProcessStartInfo(commandToExecute) { Arguments = arguments, RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true } }; return true;
}

I expected this code to work as if I would enter the above command into the shell. Which would pipe the output of gunzip into dd and dd would write it into the specified target file.

What I get here as result is that everything simply ends up as output in the shell.

How can I pipe the output into 'dd'? preferably without redirecting the standard output and flood my memory.

Any help would be appreciated. This is my first question so please have patience with me. Please ask if I left something unclear

3 Related questions 3 Reading/writing from named pipes under mono/Linux 1 Run Command From Within C# Mono Application in Linux 6 Executed piped commands via System.Diagnostics.Process on Mono Related questions 3 Reading/writing from named pipes under mono/Linux 1 Run Command From Within C# Mono Application in Linux 6 Executed piped commands via System.Diagnostics.Process on Mono 3 execute shell command with mono on raspbian 7 Running a Linux Console Command in C# 1 C# Mono start process with pipe command in linux 0 Linux process API using C# in Mono 1 How to execute Linux command line in C# Mono 0 running bash piped comand from mono linux 10 Mono hangs when trying to open a StreamWriter to a named pipe Load 7 more related questions Show fewer related questions Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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