1

I want to execute this command : iconv -f unicode -t utf8 input.txt > output.txt

But I got this error : /usr/bin/iconv: cannot open input file `>': No such file or directory

            ProcessStartInfo psi = new ProcessStartInfo();
            psi.FileName = "/usr/bin/iconv";
            psi.UseShellExecute = false;
            psi.Arguments = "-f unicode -t utf8 /tmp/test.txt > Desktop/output.txt";
            Process p = Process.Start(psi);
            p.WaitForExit();
            p.Close();
2
  • Why are you setting it to redirect standard output, and also trying to send the output to a text file? Commented Nov 5, 2015 at 20:12
  • just I was fallowing an exemple but I don't use it Commented Nov 5, 2015 at 20:14

1 Answer 1

4

You can only use the <, > and | operators inside a shell. The shell (such as bash) is what actually parses these and performs the redirection. Try this code:

...
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "/usr/bin/iconv";
psi.UseShellExecute = false;
psi.Arguments = "-f unicode -t utf8 /tmp/test.txt";
psi.RedirectStandardOutput = true;
Process p = Process.Start(psi);
Console.WriteLine(p.StandardOutput.ReadToEnd());
p.WaitForExit();
p.Close();
...

I apologize if this code doesn't work properly, I personally rarely program in C#.

You may also be able to just set psi.UseShellExecute = true. According to MSDN, this will start the program with the system shell (cmd.exe). This may work for you, although I have not tested.

Best of luck!

Sign up to request clarification or add additional context in comments.

1 Comment

Worked like a charm!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.