1

I am using a plugin for redmine called redmine checkout which gives us the option to view the code in svn repository in the redmine. Now I need to add a button which would checkout all the code in that particular project and download it to my local machine.

So I have created a batch file, its something like this:

@echo off
echo.
echo. [ SVN Updater ]

set SVNURL=%1
set SOURCE=C:\Users\
set SVN=C:\Program Files\TortoiseSVN\bin
echo.
echo. Updating %SOURCE% to SVN...
"%SVN%\TortoiseProc.exe" /command:checkout /path:"%SOURCE%" /url:%SVNURL% /closeonend:2 
echo. done.
echo.
echo. Operation complete.

This batch file performs a checkout of the code to my local machine. Now, I need to run this batch file in my redmine application. Can you please tell me where and how to run this batch file. I am a newbie.

Thank you very much in advance.

Supersonic
  • 430
  • 1
  • 11
  • 35

2 Answers2

3

You can run a batch file or any other command for that matter in many ways using system, exec, ``` (backticks),%x{}or usingopen3`. I prefer to use open3 -

require 'open3'

log = File.new("#{your_log_dir}/script.log", "w+")
command = "your_batch_file.bat"

Open3.popen3(command) do |stdin, stdout, stderr|
     log.puts "[OUTPUT]:\n#{stdout.read}\n"
     unless (err = stderr.read).empty? then 
         log.puts "[ERROR]:\n#{err}\n"
     end
end

If you want to know more about other options you can refer to Ruby, Difference between exec, system and %x() or Backticks for links to relevant documentation.

Community
  • 1
  • 1
saihgala
  • 5,724
  • 3
  • 34
  • 31
1

Ruby lets you run any shell command, batch files included and get the output using the `` operator. For example:

def run_batch_file
  `my_batch_file.bat`
end
Erez Rabih
  • 15,562
  • 3
  • 47
  • 64