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

Currently can't provide custom args when specifying a custom command #79

Closed
zachsa opened this issue Nov 24, 2021 · 6 comments
Closed
Labels

Comments

@zachsa
Copy link
Contributor

zachsa commented Nov 24, 2021

Hi,

I previously submitted a pull request for allowing for switching the command to use ogr2ogr via Docker (#60). However I've just checked now and it's not working. Looking at the code I'm actually not sure that it ever worked... I apologise!

I would like to use this feature now though, so I would like to fix it.

Looking at the run function: https://github.com/wavded/ogr2ogr/blob/master/index.ts#L147-L170, it doesn't seem like it's possible to specify an alternative command that requires args.

for example, If I try to run via docker (this is currently in the readme):

ogr2ogr('/home/.../path/to/spatial/file', {
  command: 'docker run -v /home/:/home --rm osgeo/gdal ogr2ogr',
})

Then I get an error:

  Error: spawn docker run -v /home/:/home --rm osgeo/gdal ogr2ogr ENOENT
      at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19)
      at onErrorNT (node:internal/child_process:477:16)
      at processTicksAndRejections (node:internal/process/task_queues:83:21)

In the code

    let {stdout, stderr} = await new Promise<RunOutput>((res, rej) => {
      let proc = execFile(
        command,
        args,
        {env, timeout: this.timeout, maxBuffer: this.maxBuffer},
        (err, stdout, stderr) => {
          if (err) rej(err)
          res({stdout, stderr})
        }
      )
      if (this.inputStream && proc.stdin) this.inputStream.pipe(proc.stdin)
    })

It looks like the command should actually just be docker, and the args should be ['run', '-v', etc. etc., ... then the ogr2ogr args].

But currently there is no way of specifying this

@wavded
Copy link
Owner

wavded commented Nov 29, 2021

Good point, maybe we add a commandArgs option like:

ogr2ogr('/home/.../path/to/spatial/file', {
  command: 'docker',
  commandArgs: ['run', '-v /home/:/home', '--rm', 'osgeo/gdal', 'ogr2ogr'],
  options: ['ogr2ogr args']
})

Thoughts?

@zachsa
Copy link
Contributor Author

zachsa commented Dec 1, 2021

I will have a look sometime this week and make a pull request

@github-actions
Copy link

github-actions bot commented Jan 1, 2022

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the stale label Jan 1, 2022
@github-actions
Copy link

github-actions bot commented Jan 6, 2022

This issue was closed because it has been stalled for 5 days with no activity.

@github-actions github-actions bot closed this as completed Jan 6, 2022
@zachsa
Copy link
Contributor Author

zachsa commented Jan 14, 2022

Sorry, I never got round to this

@jgrocha
Copy link

jgrocha commented May 31, 2023

One possible workaround is to create a small shell script that receives all parameters.

cat /usr/local/bin/dk_ogr2ogr.sh 
#!/bin/bash

docker run -v /tmp:/data --rm osgeo/gdal ogr2ogr $@

Then use the script, using options['command'] = "/usr/local/bin/dk_ogr2ogr.sh"

It works, but it would be nice to support this on ogr2ogr module.

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

No branches or pull requests

3 participants