How to set input + output params to run external app?


I’d like to run Tidy to clean up XML files*, but I can’t figure out the right syntax.

This does nothing:

system("c:\tidy.exe","-utf8 -indent -xml < input.txt > output.txt")

Thank you.

  • I tried installing the Ruby gem, but it failed with “MSYS2 could not be found. Please run ‘ridk install’ or download and install MSYS2 manually from

The backtick did the trick:

result = ``tidy.exe -utf8 -indent -xml -o input.txt output.txt
(I had to put two backticks because this forum uses backticks to format code).

However, I had to copy tidy.exe in the local directory: It looks like the command was run in c:, triggering an error:

``’: Permission denied - c: idy.exe -utf8 -indent -xml -o input.txt output.txt (Errno::EACCES)

I guess system() ran the command in c:, and tried writing the output there… and failed since a non-admin app can’t write in c:\


You shouldn’t need to move tidy.exe, as the system will locate it through the path. But you should be able to specify the input and output file locations relative to your current directory.

This worked:

COMMAND = "c:\\tidy.exe -utf8 -indent -xml -o %s %s" % ["output.txt", "input.txt"]
#Returns true if the command was found and run successfully, false otherwise.
result = system( COMMAND )
if result
	puts "Command ran OK"
	puts "Command failed"

Ruby has a lot of different ways to run an external command:

There are a couple of Ruby Gems that package the Tidy library. This would mean you’d get the functionality of Tidy inside Ruby, and you wouldn’t need to shell out to it. I don’t know if they work on Windows, however…