I have a little problem with star character in my command for linux – I need to find out distro. When I replace this character witch e.g. ‘fedora’ then this command gives good results. In this case it write something like this: /bin/cat: /etc/*-release: Directory or file doesn’t exist.
My code is:
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "cat";
p.StartInfo.Arguments = "/etc/*-release";
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Thanks in advance for your answer.
Matej
When you run
cat /etc/*-releasefrom your shell, the shell is responsible for expanding the*to a list of matching files, if any.When you directly execute a program yourself (as you’re doing here with the
Processinterface), you need to re-create the shell’s behavior yourself. This is actually for the best, as it is a bit silly to runcatto read a file from a full-featured programming language — surely the language provides something easy for the logical equivalent of:You can use whatever mechanism you like to replace the
glob()bit there; a fellow stacker has provided his ownglob()mechanism in another answer.