簡體   English   中英

在nodejs中執行shell命令

[英]execute a shell command in nodejs

我試圖在nodejs script.it中執行以下shell命令在終端中正常工作

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

節點腳本

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


    });

正在執行上面的代碼

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

我怎樣才能解決這個問題

加倍反斜杠:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM