Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print ogr2ogr CLI version #107

Closed
molynerd opened this issue Jul 16, 2024 · 2 comments · Fixed by #108
Closed

Print ogr2ogr CLI version #107

molynerd opened this issue Jul 16, 2024 · 2 comments · Fixed by #108

Comments

@molynerd
Copy link
Contributor

In order to validate that my local machine and deployed environment are running the same version of ogr2ogr, it would be nice if this lib had an easy way to print out the details from ogr2ogr --version.

Yes, one could use child_process to run a shell and attempt to gather this information separately, but there isn't a guarantee that child_process and this lib will find the same CLI executable. Additionally, the implementer of this lib would be required to know the path to the ogr2ogr executable, which is already taken care of by the lib.

Possible solution:

import ogr2ogr from 'ogr2ogr'

console.log(ogr2ogr.version());

// GDAL 3.9.0, released 2024/05/07

I have tried using existing functionality, but I'm not able to get around an issue where the lib expects a path to be passed in for the file I'm operating on (in this case, there is no file). Strangely, the command the lib spits out actually does work when run separately, but doesn't work in the lib.

const m = require('ogr2ogr').default;

m('/path/to/a/real/file', {command: '/opt/homebrew/bin/ogr2ogr --version'}).then(console.log);
> Uncaught Error: spawn /opt/homebrew/bin/ogr2ogr --version ENOENT
    at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
    at __node_internal_errnoException (node:internal/errors:623:12)
    at ChildProcess._handle.onexit (node:internal/child_process:284:19)
    at onErrorNT (node:internal/child_process:477:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn /opt/homebrew/bin/ogr2ogr --version',
  path: '/opt/homebrew/bin/ogr2ogr --version',
  spawnargs: [
    '-f',
    'GeoJSON',
    '-skipfailures',
    '/vsistdout/',
    '/Users/nicholas.molyneux/Downloads/X.pdf'
  ],
  cmd: '/opt/homebrew/bin/ogr2ogr --version -f GeoJSON -skipfailures /vsistdout/ /path/to/a/real/file'
}

the command /opt/homebrew/bin/ogr2ogr --version -f GeoJSON -skipfailures /vsistdout/ /path/to/a/real/file does actually work separately.

$ /opt/homebrew/bin/ogr2ogr --version -f GeoJSON -skipfailures /vsistdout/ /path/to/a/real/file
GDAL 3.9.0, released 2024/05/07
@wavded
Copy link
Owner

wavded commented Jul 17, 2024

I like this idea, should be fairly simple to add. Care to take a swing at a PR?

@molynerd
Copy link
Contributor Author

molynerd commented Aug 8, 2024

I like this idea, should be fairly simple to add. Care to take a swing at a PR?

yeah I'll give it a shot! might take me a while though ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants