Opened 5 years ago
Last modified 5 years ago
#13321 new Bugs
boost::process: executable extension is required to create a process.
Reported by: | Owned by: | Beman Dawes | |
---|---|---|---|
Milestone: | To Be Determined | Component: | filesystem |
Version: | Boost 1.65.0 | Severity: | Problem |
Keywords: | Cc: |
Description
The following code does not assert under Windows:
int main( int argc, char* argv[] ) { try { boost::process::child p( "cmd" ); p.terminate(); } catch (...) { assert( false ); } try { boost::process::child p( "cmd.exe" ); p.terminate(); } catch (...) { assert( false ); } return 0; }
So, apparently, .exe does not need to be specified.
However, the following code does assert when .exe is not specified:
int main( int argc, char* argv[] ) { if ( argc == 1 ) { std::string exe = argv[0]; try { std::string exeNoExt = exe.substr(0, exe.find_last_of(".")); boost::process::child p( exeNoExt, "foo" ); p.terminate(); } catch (...) { assert( false ); // asserts } try { boost::process::child p( exe, "foo" ); p.terminate(); } catch (...) { assert( false ); // does not assert } }
boost::process::child p( exeNoExt, "foo" ); should work and executable extention should be silently added, like it is for cmd.
Note that boost::process::search_path( "myprg" ) returns "myprg.exe" if found, so here, extension is added correctly. But it's unsafe to systematically call this function priori to creating a child as it only works with program names (calling it with "Myfolder/myprg" returns "").