I have a project , running from c:\work\SomeVariantFolder\MySolution\MyProject\Bin\Debug, and I need to execute a command line from this project from one of the subfolders : c:\work\SomeVariantDev. The problem I am facing is to get from the folder where my project running from to the folder where i am suppose to run this command line from.
Please note that I can't use batch file for this solution.
What I've tried to do - declare a private method which execute three commands from the same process, going four folders up and then execute my command, but that doesn't seem to work. I feel like I'm doing something wrong here because if I run this command from c:\work\SomeVariantFolder\ it wroks well.
var process = new System.Diagnostics.Process();
var startInfo = new System.Diagnostics.ProcessStartInfo
{
WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal,
FileName = "cmd.exe",
RedirectStandardInput = true,
UseShellExecute = false
};
process.StartInfo = startInfo;
process.Start();
process.StandardInput.WriteLine("cd..");
process.StandardInput.WriteLine("cd..");
process.StandardInput.WriteLine("cd..");
process.StandardInput.WriteLine("cd..");
process.StandardInput.WriteLine("my command");
Please note that due the nature of my solution I can't use batch files and can't use c:\work\SomeVariantFolder as a hard coded folder since "SomeVariantFolder" name may change under some circumstances.
Any help would be appriciated
Use the Copy Command to Transfer Specific Files To copy files, use the copy command from the command line. copy c:\myfile. txt e: The command above will copy "myfile.
Copy a Directory and Its Contents ( cp -r ) Similarly, you can copy an entire directory to another directory using cp -r followed by the directory name that you want to copy and the name of the directory to where you want to copy the directory (e.g. cp -r directory-name-1 directory-name-2 ).
To copy multiple files you can use wildcards (cp *. extension) having same pattern. Syntax: cp *.
Try setting the WorkingDirectory
property of ProcessStartInfo
to sets the initial directory for the process to be started.
var startInfo = new System.Diagnostics.ProcessStartInfo
{
WorkingDirectory = @"The\Process\Working\Directory",
WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal,
FileName = "cmd.exe",
RedirectStandardInput = true,
UseShellExecute = false
};
References: ProcessStartInfo.WorkingDirectory Property
System.Environment.CurrentDirectory = @"..\..\..";
System.Diagnostics.Process.Start("MyCommand", "arg1, arg2, arg3");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With