This is likely because the output is being sent to STDERR, not STDOUT (which is all %x
captures). Because you’re not capturing it, it does what it would normally and prints to the console.
You can either redirect STDERR to STDOUT in your command:
%x(svn lock #{@path}/#{@file} 2>&1)
Or use Open3 to capture both STDOUT & STDERR:
require 'open3'
Open3.popen3("svn lock #{@path}/#{@file}") do |stdin, stdout, stderr, wait_thr|
puts "stdout is:" + stdout.read
puts "stderr is:" + stderr.read
end
The first option offloads the work to the shell executing the command and depending on the environment it may not support it. As such using Open3 is a much more portable solution.
Some additional notes: note I’ve removed the unnecessary interpolation in your %x
statement. Also, consider using ShellWords to properly escape interpolated string in shell commands. This is particularly important if these are user-inputted strings.