I am trying to execute a command through c#. I pass a command as a parameter through a function which then executes it on my terminal in VS Code. When I pass the command 'ps'
it works, but when I pass the command 'ls - all'
it gives me the error: A parameter cannot be found that matches parameter name 'all'. I think it probably has to do something with the space, but I'm not sure. I don't know how to solve it. This is the function I use to pass the command and execute it:
public void ExecuteCommand(string key) {
System.Diagnostics.Process process = new System.Diagnostics.Process();
try {
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = @"powershell.exe";
startInfo.Arguments = "/c " + key;
process.StartInfo = startInfo;
process.Start();
process.Close();
}
catch {
Console.WriteLine("Error occured");
}
Console.WriteLine("Command executed");
}
You have to use the command ls -Force
to list all the files including the hidden files.ls -al
works in linux.