简体   繁体   中英

execute a shell command in nodejs

Am trying to execute following shell command in nodejs script.it is working fine in terminal

    find -type f -printf %T+\t%p\n | sort -n

node script

 var command = ' cd ~/home'
              command +=' find -type f -printf %T+\t%p\n | sort -n'
        exec(command, function (error, stdout, stderr) {       


    });

while executing the above code am getting

exec error: Error: Command failed: /bin/sh: 2: Syntax error: "|" unexpected

How can i solve this eroor

加倍反斜杠:

command +='find -type f -printf %T+\\t%p\\n | sort -n'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM