Changeset 35698 for main/trunk/search4j/libsearch4j.cpp
- Timestamp:
- 2021-10-24T23:44:10+13:00 (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/search4j/libsearch4j.cpp
r33930 r35698 4 4 5 5 #include "libsearch4j.h" 6 7 6 8 7 #ifdef WINDOWS … … 68 67 69 68 70 int process_and_catch_output( string command, string &output ) {69 int process_and_catch_output( string command, string& output ) { 71 70 72 71 FILE *pPipe; … … 90 89 /* Read pipe until end of file. */ 91 90 while( !feof( pPipe ) ) { 92 char psBuffer[ 128];91 char psBuffer[512]; 93 92 //if ( verbose ) cout << "get some data" << endl; 94 if( fgets( psBuffer, 128, pPipe ) != NULL ) {93 if( fgets( psBuffer, sizeof(psBuffer), pPipe ) != NULL ) { 95 94 96 95 //if ( verbose ) cout << "got: " << psBuffer << endl; … … 239 238 } 240 239 241 int Jvm::getEra(){ return era_; }242 int Jvm::getMajor(){ return major_; }243 int Jvm::getMinor(){ return minor_; }244 int Jvm::getUpdate() { return update_; }245 246 bool Jvm::getIsJdk() { return isJdk_; }247 bool Jvm::getIsJre() { return !isJdk_; }240 int Jvm::getEra() { return era_; } 241 int Jvm::getMajor() { return major_; } 242 int Jvm::getMinor() { return minor_; } 243 int Jvm::getUpdate() { return update_; } 244 245 bool Jvm::getIsJdk() { return isJdk_; } 246 bool Jvm::getIsJre() { return !isJdk_; } 248 247 249 248 void Jvm::setVersionFromExeOuput() { … … 519 518 520 519 520 521 if ( !jvmFound ) { 522 //look for it on PATH 523 if ( verbose ) cout << " - Looking on PATH (possibly yielding a pseudo, but passable, JAVA_HOME such as /usr): "; 524 525 #ifdef WINDOWS 526 // The following is the DOS equivalent to 'which java', however note that 527 // 'where' returns a list of all possible matches (one per line) 528 const char* cmd = "where java 2>nul"; 529 #else 530 const char* cmd = "which java 2>/dev/null"; 531 #endif 532 char full_path_java[512] = { '\0' }; // empty string 533 534 // **** 535 // Consider replacing the following code with a call to process_and_catch_output(command, output) 536 // but would need extending to have extra (optional) argument 'only_first_list' which defaults to 'false' 537 538 FILE* PIN = popen(cmd,"r"); 539 if (PIN == NULL) { 540 cerr << "Failed to run the command to locate 'java' on PATH" << endl; 541 cerr << "Command run was: " << cmd << endl; 542 } 543 else { 544 // Only need the first line of output 545 546 // Returns number of chars returned. OK to ignore here 547 if (fgets(full_path_java, sizeof(full_path_java), PIN) == NULL) { 548 // Not strictly necessary (as already initialized to be the empty string when declared) 549 // but done to void the warning g++ gives about not checking the return value 550 full_path_java[0] = '\0'; 551 } 552 } 553 554 // Not all implmentations of 'which' are coded to return 0 if a program match is found 555 // => safer just to look to see if a non-empty string is returned 556 557 int ignore_exit_val = pclose(PIN); 558 559 if ( strcmp(full_path_java,"") != 0) { 560 // go two directories up from where 'java' was found 561 javaHomeEnv = dirname(dirname(full_path_java)); 562 563 // Logic from here same as for other search4j java/javac testing 564 if ( verbose ) cout << "(" << javaHomeEnv << ") "; 565 jvm.setJavaHome( javaHomeEnv ); 566 if ( jvm.check() ) { 567 if ( use_minimum ) { 568 if ( jvm.compare( minimum ) >= 0 ) { 569 jvmFound = true; 570 } 571 } else { 572 jvmFound = true; 573 } 574 } 575 if ( (jreOnly && !jvm.getIsJre() ) || (jdkOnly && !jvm.getIsJdk()) ) { 576 jvmFound = false; 577 } 578 579 } 580 if ( verbose ) { if( jvmFound ) cout << "yes" << endl; else cout << "no" << endl; } 581 } 582 583 521 584 return jvmFound; 522 585 }
Note:
See TracChangeset
for help on using the changeset viewer.