我有安装了命令行界面的Tortoise SVN。安装路径为CREATE TABLE `operators` (
`id` varchar(45) NOT NULL,
`name` int(11) NOT NULL,
`adress_id` int(11) NOT NULL,
`land_id` int(11) NOT NULL,
`contact_id` int(11) NOT NULL,
`operator_category_id` int(11) NOT NULL,
`legal_form` varchar(45) DEFAULT NULL,
`affidavit` varchar(45) DEFAULT NULL,
`comment` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`),
KEY `operator_category_fk_idx` (`operator_category_id`),
KEY `contact_id_idx` (`contact_id`),
KEY `adress_id_idx` (`adress_id`),
KEY `land_id_idx` (`land_id`),
CONSTRAINT `adress_id` FOREIGN KEY (`adress_id`) REFERENCES `adresses` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `contact_id` FOREIGN KEY (`contact_id`) REFERENCES `contacts` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `land_id` FOREIGN KEY (`land_id`) REFERENCES `lands` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `operator_category_fk` FOREIGN KEY (`operator_category_id`) REFERENCES `operator_category` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
)
,每当我使用任何SVN命令时,都会使用C:\Program Files\TortoiseSVN\bin
。
我开发了一个Ruby Windows应用程序,它作为后台进程运行。此应用程序运行像
这样的命令svn.exe
正如我所提到的,此命令会调用svn info "#{path_to_repository}"
。
问题是,svn.exe
闪烁一个命令提示符并终止,因此如果我为十个不同的存储库运行svn.exe
十次,那么当该命令开发运行时,屏幕会闪烁十次及时地,屏幕定期闪烁十次。
我需要的是一种通过Tortoise SVN运行SVN命令的方法,而svn info
不会弹出屏幕并关闭。
答案 0 :(得分:6)
Ruby has numerous way of executing command in shell,在GUI App中使用时,所有选项都会显示命令行弹出窗口。
根据您在svn info
中查找的详细信息,您可以使用WebSVN之类的选项,看看是否可以抓取GUI或从其RSS源获取数据。 Take a look at demo site of this product
如果您有非常具体和最小的需求,那么,您还可以选择构建一个可以使用命令行查询subversion服务器的小型REST API。在这种情况下,您可以调用REST API来获取数据并避免弹出command
窗口。
如果您的时间非常短或者没有服务器基础结构来托管REST API,那么您可以考虑创建一个运行套接字服务器的Ruby应用程序,并且可以在从客户端接收命令时运行shell命令。然后,您可以使用套接字客户端使GUI应用程序连接到套接字服务器,并要求服务器应用程序执行svn info
并返回结果。 Go through the tutorial on building such interacting apps。然后,您可以选择在同一台PC上并排运行它们。
另一种方法是使用Ruby SVN bindings。可能需要一些digging around才能使其发挥作用。
以下是快速入门代码:
server.rb - 一个ruby TCP服务器,它接受命令并在shell中执行它们
require 'socket'
server = TCPServer.open(2000) # Socket to listen on port 2000
puts "Listening now #{server.addr}"
loop {
Thread.start(server.accept) do |client|
cmd = client.gets
puts "Processing #{cmd} from #{client.peeraddr}"
IO.popen(cmd) { |s| result = [];
while (line = s.gets) do
client.puts line.chop
end;
}
client.close
end
}
app.rb Shoes GUI app向svn info
正在运行的TCP服务器发出server.rb
命令
要求' socket'
Shoes.app {
stack do
@push = button "Get SVN Info"
@note = para ""
end
@push.click {
hostname = 'localhost'
port = 2000
result = []
s = TCPSocket.open(hostname, port)
s.puts "svn info trunk/backend"
while line = s.gets
result << line.chop
end
s.close
@note.replace result.join("\n")
}
}
应使用app.rb
命令启动 shoes app.rb
。
答案 1 :(得分:5)
此行为不是特定于Ruby而是特定于Windows命令行解释器。有几种方法可以解决它。
svn
的{{1}}命令,该命令不应闪烁命令提示符窗口。其变体是使用cmd.exe /C
作为前缀。这在所有情况下都不起作用,我没有方便的Windows上的Ruby检查。start /min
包装器。由于命令行解释器不处理.vbs
,因此不会创建其窗口。有关详细信息,请参阅“How to run a batch file without launching a 'command window'?”。最好的选择是使用WinAPI包装器gem来访问非常灵活的.vbs
函数:
ShellExecute
此示例取自“Launching Apps and Printing Docs with the Windows Shell”,您可以在其中找到更多详细信息。
出于您的目的,它将类似于
require 'win32ole'
# Create an instance of the Windows Shell object...
shell = WIN32OLE.new('Shell.Application')
# The shell object's ShellExecute method performs a specified operation on a specified file. The syntax is...
shell.ShellExecute(FILE, ARGUMENTS, DIRECTORY, OPERATION, SHOW)
详细了解ShellExecute
用法。