为什么我不能在 Ruby 中使用反引号/反引号方法调用 javac? [英] Why can't I call javac using the Backquotes/Backticks approach in Ruby?

查看:51
本文介绍了为什么我不能在 Ruby 中使用反引号/反引号方法调用 javac?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 Ruby 脚本编译 Java 源文件.但是我对以下行为感到有些困惑

I am trying to compile a java source file via a Ruby Script. However I am a bit puzzled by the following behavior

compile_results = `javac  #{source_file}`

这无法运行,并出现没有这样的文件..."错误.我弹出了irb

this fails to run with a 'No such file...' error. I popped up irb

irb(main):001:0> `javac -help`
Errno::ENOENT: No such file or directory - javac -help
        from (irb):1:in ``'
        from (irb):1

irb(main):002:0> `csc`
=> "Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.3053\nfor Microsoft
 (R) Windows (R) 2005 Framework version 2.0.50727\nCopyright (C) Microsoft Corpo
ration 2001-2005. All rights reserved.\n\nfatal error CS2008: No inputs specifie
d\n"

然而,javac 和 csc 都在 PATH 上.例如如果我从运行 ruby​​ 脚本的 shell 手动运行 javac,我就可以访问 java 编译器.源文件存在.

However both javac and csc are on the PATH. e.g. if i run javac manually from the shell that I run the ruby script from, I am able to get to the java compiler. The source file exists.

我尝试了 ruby​​ 1.8.7 和 1.9.1 (Windows).有没有人看到我遗漏的东西?

I tried both ruby 1.8.7 and 1.9.1 (Windows). Does anyone see something that I am missing ?

更新:我不认为它与命令行参数有关.相反,由于某种奇怪的原因,它无法访问 javac.我将行 javac %1 放在批处理文件中,并以通常的方式调用批处理文件.这有效......但仍然不确定javac的整个问题是什么.

Update: I dont think it has to do with command line args. Rather it can't get to javac for some weird reason. I put the line javac %1 in a batch file and call the batch file in the usual way. This worked... but still am not sure of what the whole issue was with javac.

推荐答案

似乎 Ruby on Windows 不喜欢

It seems that Ruby on Windows doesn't like the

`command -with-args`

语法.你可以试试

%x[javac -help]

%x[javac #{source_file}]

system 'javac', '-help'

system 'javac', "#{source_file}"

这篇关于为什么我不能在 Ruby 中使用反引号/反引号方法调用 javac?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆