所以我有一个在另一个脚本上运行测试用例的脚本。我正在尝试在运行测试用例时重定向 stderr。给我带来问题的部分是读取命令:
在脚本1中:
read -p "Delete $file? (y/n) " input
Run Code Online (Sandbox Code Playgroud)
在测试脚本中:
$script $opts $file 2>/dev/null
Run Code Online (Sandbox Code Playgroud)
来自 script1 的读取调用也会被重定向。
嘿那里,我被困住了.我已经在代码中遇到了2个问题,但我对如何解决问题感到茫然.作业大多是胡说八道:
import java.util.*;
class Business {
private String name, phone;
private int employees, age;
void Business(){
name = "Foo Inc.";
phone = "";
employees = 0;
age = 0;
System.out.println("In default constructor!");
printVals();
}
void Business(String name, String phone, int employees){
System.out.printf("%s %s %d\n", name, phone, employees);
this.name = name;
this.phone = phone;
this.employees = employees;
this.age = 0;
System.out.println("In constructor!");
printVals();
}
void printVals(){
System.out.printf("name: %s\n", name);
System.out.printf("phone: %s\n", phone);
System.out.printf("employees: %d\n", employees);
System.out.printf("age: %d\n", age);
}
public static …Run Code Online (Sandbox Code Playgroud) 我正在尝试检查磁盘或磁盘映像是否为"空".我假设如果第一个1mb和最后一个1mb是零则这是真的.我开始尝试重新创建,hexdump但此时似乎有点啰嗦.
这是我的代码:
open DISK, $disk or die $!;
for( 1 .. 1024 ) {
$buffer = undef;
sysread(DISK, $buffer, 1024, 0) or last;
for ( split //, $buffer ) {
if( ord($_) =~ /[^0]/ ) {
$flag++;
}
}
}
Run Code Online (Sandbox Code Playgroud)
有一个更好的方法吗?
我正在接收来自某个进程的输出,我希望使用perl从该进程的输出中搜索特定元素,如下所示,但即使有元素,它仍然返回FALSE.我认为我在解析时遇到了错误帮助任何指针.谢谢
流程输出:
origin-server-pool-1
http_TestABC
https_TestABC
Run Code Online (Sandbox Code Playgroud)
脚本:
use strict;
use warnings;
my @result_listosp; #assigned from output process given above
my $osp="http_TestABC";
my $status_osp_check= check_if_entity_exists($osp,@result_listosp);
print $status_osp_check;
sub check_if_entity_exists()
{
my $entity = shift;
my @entityarray = @_;
my $status="FALSE";
if ( grep { $_ eq $entity} @entityarray) {
$status="TRUE";
return $status;
}
else {
return $status;
}
}
Run Code Online (Sandbox Code Playgroud) 我目前正在尝试将用户参数(通常为2)作为文本文件,从文本文件中获取字符,行和单词的数量并将其显示回来.我的代码目前将它们全部加在一起,而不是为每个文件单独列出它们.如何根据用户参数列出文件名,以及每个文件的行数,字符数和单词数,而不将它们一起添加?感谢您花时间阅读本文.
#!usr/bin/perl -w
use strict;
my $user_files = @ARGV;
chomp($user_files);
my @parts;
my $word_count = 0;
my $total_words = 0;
my $line_count = 0;
foreach my $line (<>)
{
@parts = split (/\s+/,$line);
$line_count += (line =~tr/\n//);
$word_count += length($line) + 1;
$total_words += scalar(@parts);
}
for(my $i = 0; $i < 1; $i++)
{
print "File name:", @ARGV,
"\t\t Word Count: ", $word_count,
"\t\t Total words: ", $total_words,
"\t\t Total lines: ", $line_count,
"\n";
}
Run Code Online (Sandbox Code Playgroud)