微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Node.js child_process仅在Ubuntu 16中添加sudo的情况下成功运行命令

如何解决Node.js child_process仅在Ubuntu 16中添加sudo的情况下成功运行命令

我无法使用child_process运行脚本。相同的命令适用于Terminal或在其前面添加sudo时使用。我不希望添加sudo,因为它希望它自动运行。下面是我的代码

var cmd_saga = 'grid_spline 4 ' +
    '-TARGET_DEFinitioN 0 -SHAPES "' + shapefile + '" -FIELD "' + short_param + '" -METHOD 1 ' +
    '-EPSILON 0.0001 -LEVEL_MAX 14 -TARGET_USER_SIZE 0.01 -TARGET_USER_FITS 1 ' +
    '-TARGET_OUT_GRID "' + saga_path + '"';

const { spawnSync } = require( 'child_process' );
const sag = spawnSync('saga_cmd',cmd_saga.split(' '));

console.log( `stderr: ${sag.stderr.toString()}` );
console.log( `stdout: ${sag.stdout.toString()}` );

下面是我在没有sudo的情况下运行它的错误消息:

stderr: Error: input file [/home/user/apps/app/temp/ApDy5Icw0anTkX7-AAAD/1599095530195.shp]
Error: Points

stdout: ____________________________

   #####   ##   #####    ##
  ###     ###  ##       ###
   ###   # ## ##  #### # ##
    ### ##### ##    # #####
 ##### #   ##  ##### #   ##
____________________________

SAGA Version: 2.3.1

____________________________
library path: /usr/lib/x86_64-linux-gnu/saga/
library name: libgrid_spline
library     : Spline Interpolation
tool        : Multilevel B-Spline Interpolation
author      : O.Conrad (c) 2006
processors  : 24 [24]
____________________________

Load shapes: /home/user/apps/app/temp/ApDy5Icw0anTkX7-AAAD/1599095530195.shp...
Failed

Usage: saga_cmd grid_spline 4 [-SHAPES <str>] [-FIELD <str>] [-TARGET_DEFinitioN <str>] [-TARGET_USER_SIZE <double>] [-TARGET_USER_XMIN <double>] [-TARGET_USER_XMAX <double>] [-TARGET_USER_YMIN <double>] [-TARGET_USER_YMAX <double>] [-TARGET_USER_FITS <str>] [-TARGET_TEMPLATE <str>] [-TARGET_OUT_GRID <str>] [-METHOD <str>] [-EPSILON <double>] [-LEVEL_MAX <num>]
  -SHAPES:<str>                 Points
    Shapes (input)
  -FIELD:<str>                  Attribute
    Table field
  -TARGET_DEFinitioN:<str>      Target Grid System
    Choice
    Available Choices:
    [0] user defined
    [1] grid or grid system
    Default: 0
  -TARGET_USER_SIZE:<double>    Cellsize
    Floating point
    Minimum: 0.000000
    Default: 1.000000
  -TARGET_USER_XMIN:<double>    Left
    Floating point
    Default: 0.000000
  -TARGET_USER_XMAX:<double>    Right
    Floating point
    Default: 100.000000
  -TARGET_USER_YMIN:<double>    Bottom
    Floating point
    Default: 0.000000
  -TARGET_USER_YMAX:<double>    Top
    Floating point
    Default: 100.000000
  -TARGET_USER_FITS:<str>       Fit
    Choice
    Available Choices:
    [0] nodes
    [1] cells
    Default: 0
  -TARGET_TEMPLATE:<str>        Target System
    Grid (optional input)
  -TARGET_OUT_GRID:<str>        Target Grid
    Grid (output)
  -METHOD:<str>                 Method
    Choice
    Available Choices:
    [0] without B-spline refinement
    [1] with B-spline refinement
    Default: 1
  -EPSILON:<double>             Threshold Error
    Floating point
    Minimum: 0.000000
    Default: 0.000100
  -LEVEL_MAX:<num>              Maximum Level
    Integer
    Minimum: 1
    Maximum: 14
    Default: 11

grid_spline 4 -TARGET_DEFinitioN 0 -SHAPES "/home/user/apps/app/temp/ApDy5Icw0anTkX7-AAAD/1599095530195.shp" -FIELD "chlorophyl" -METHOD 1 -EPSILON 0.0001 -LEVEL_MAX 14 -TARGET_USER_SIZE 0.01 -TARGET_USER_FITS 1 -TARGET_OUT_GRID "/home/user/apps/app/temp/ApDy5Icw0anTkX7-AAAD/1599095530195.sdat"

我还使用sudo chmod 755chmod +x *文件夹和文件制成了可执行文件

有什么方法可以使它在没有sudo的情况下运行?我愿意使用其他任何可用的库。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。