我正在尝试运行命令,即:通过Java的mvn -version,但我不断收到以下错误:
public InputStream runCommand() {
try {
ProcessBuilder processBuilder = new ProcessBuilder("mvn -version");
Process process = processBuilder.start();
try {
process.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String s = null;
while((s = bufferedReader.readLine())!= null){
System.out.println(s);
}
System.out.println();
return process.getInputStream();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
我知道此命令有效,因为我已经对其进行了手动测试。这是运行命令的代码:
AP4_Track *test_videoTrack = nullptr;
AP4_ByteStream *input = nullptr;
AP4_Result result = AP4_FileByteStream::Create(filename, AP4_FileByteStream::STREAM_MODE_READ, input);
AP4_File m_file (*input, true);
//
// Read movie tracks, and metadata, find the video track
size_t index = 0;
uint32_t m_width = 0, m_height = 0;
auto item = m_file.GetMovie()->GetTracks().FirstItem();
auto track = item->GetData();
if (track->GetType() == AP4_Track::TYPE_VIDEO)
{
m_width = (uint32_t)((double)test_videoTrack->GetWidth() / double(1 << 16));
m_height = (uint32_t)((double)test_videoTrack->GetHeight() / double(1 << 16));
std::string codec("unknown");
auto sd = track->GetSampleDescription(0);
AP4_String c;
if (AP4_SUCCEEDED(sd->GetCodecString(c)))
{
codec = c.GetChars();
}
// Find and instantiate the decoder
AP4_Sample sample;
AP4_DataBuffer sampleData;
test_videoTrack->ReadSample(0, sample, sampleData);
}
有人可以指出我在做什么错吗?
答案 0 :(得分:1)
public class LRBDemo {
public static void main(String[] args) {
// загрузить комплект ресурсов по умолчанию
ResourceBundle rd = ResourceBundle.getBundle(SampleRB.class.getName());
System.out.println("Английская версия программы: ");
System.out.println("Строка по ключу Title: " + rd.getString("title"));
System.out.println("Строка по ключу StopText: " + rd.getString("StopText"));
System.out.println("Строка по ключу StartText: " + rd.getString("StartText"));
// загрузить комплект ресурсов для поддержки немецкого языка
rd = ResourceBundle.getBundle(SampleRBde.class.getName());
System.out.println("\nНемецкая версия программы: ");
System.out.println("Строка для ключа Title: " + rd.getString("title"));
System.out.println("Строка по ключу StopText: " + rd.getString("StopText"));
System.out.println("Строка по ключу StartText: " + rd.getString("StartText"));
}
}
并未按照您的意图运行带有参数new ProcessBuilder("mvn -version")
的{{1}}。而是尝试运行名为mvn
的程序。即,程序名称本身具有两个单词,并且两个单词之间有一个空格。没有这样的程序是很有意义的! :-)
请注意,ProgramBuilder的构造函数takes a String...
argument用于提供程序名称和参数。您想要的是:-version
。