Changeset 22529

Show
Ignore:
Timestamp:
30.07.2010 15:35:04 (9 years ago)
Author:
sjm84
Message:

Fixed Windows from trying to write a file into a possibly inaccessible place

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/search4j/libsearch4j.cpp

    r20709 r22529  
    7070int process_and_catch_output( string command, string &output ) { 
    7171     
    72     #ifdef WINDOWS 
    73  
    74     char cmd[1024] = "cmd.exe /c "; 
    75     strcat(cmd, command.c_str()); 
    76     strcat(cmd, " > cmd_output.txt 2>&1"); 
    77     //cerr << "command: " << cmd << endl; 
    78     int code = process( cmd, false ); 
    79     if ( code!= 0 ) 
    80         return code; 
    81      
    82     string line; 
    83     ifstream myfile("cmd_output.txt"); 
    84     if ( !myfile.is_open() ) { 
    85         return -1; 
    86     } 
    87  
    88     while ( !myfile.eof() ) { 
    89         getline(myfile,line); 
    90         output.append( line ); 
    91     } 
    92  
    93     myfile.close(); 
    94      
    95     _unlink( "cmd_output.txt" ); 
    96      
    97     return code; 
    98  
    99     #else 
    100      
    10172    FILE *pPipe; 
    10273 
     
    10677 
    10778    //if ( verbose ) cout << "process(): running '" << command << "'" << endl; 
     79#ifdef WINDOWS 
     80    if( (pPipe = _popen( cmd, "rt" )) == NULL ) { 
     81        _pclose( pPipe ); 
     82#else 
    10883    if( (pPipe = popen( cmd, "r" )) == NULL ) { 
    109         //if ( verbose ) cout << "could not start process" << endl; 
    11084        pclose( pPipe ); 
     85#endif 
    11186        return -1; 
    11287    } 
    113  
    11488    //if ( verbose ) cout << "started process" << endl; 
    11589 
     
    130104 
    131105    /* Close pipe and return return value of pPipe. */ 
     106#ifdef WINDOWS 
     107    int code = _pclose( pPipe ); 
     108#else 
    132109    int code = pclose( pPipe ); 
     110#endif 
     111 
    133112    return code; 
    134  
    135     #endif 
    136113 
    137114}