通过perl调用java方法,并在不使用内置函数的情况下获取返回值
我有一个Java程序,它有一个静态方法通过perl调用java方法,并在不使用内置函数的情况下获取返回值,java,perl,Java,Perl,我有一个Java程序,它有一个静态方法 private static int checkURL(String currentURL) 从我的perl脚本中,我想调用这个方法并获取这个方法的返回值 我有一个限制,我不能使用CPAN提供的任何内置Perl模块 我想在Perl中通过system()命令调用Java,但问题是如何调用此方法并获取返回代码?调用外部命令并返回结果(直接从) 使用模块 也是一个著名的Java/Perl集成模块 编辑:我有一个限制,我不能使用CPAN提供的任何内置
private static int checkURL(String currentURL)
从我的perl脚本中,我想调用这个方法并获取这个方法的返回值
我有一个限制,我不能使用CPAN提供的任何内置Perl模块
我想在Perl中通过system()命令调用Java,但问题是如何调用此方法并获取返回代码?调用外部命令并返回结果(直接从) 使用模块 也是一个著名的Java/Perl集成模块 编辑:我有一个限制,我不能使用CPAN提供的任何内置perl模块 哦,对不起,我没看到。不久前我试过下面的方法
Hello.java
class Hello {
// Your program begins with a call to main().
public static void main(String args[]) {
System.out.println("This is a simple Java program to test return code.\n");
System.exit(100);
}
}
test.pl
#!/usr/bin/perl
use strict;
use warnings;
my $command = "java Hello";
print "Command is $command:\n";
system($command);
my $retval = $? >> 8;
print "The return code is $?\n";
print "retval is $retval\n";
运行它
perl test.pl
输出
Command is java Hello:
This is a simple Java program to test return code.
The return code is 25600
retval is 100
如果它是一个私有方法,您甚至会如何在Java中调用它?
#!/usr/bin/perl
use strict;
use warnings;
my $command = "java Hello";
print "Command is $command:\n";
system($command);
my $retval = $? >> 8;
print "The return code is $?\n";
print "retval is $retval\n";
Command is java Hello:
This is a simple Java program to test return code.
The return code is 25600
retval is 100