アプリのフォルダーを毎日クリーンアップする必要があるため、そのために (スーパーユーザーの助けを借りて) bash スクリプトを作成しました。
コンソールからはうまく機能しますが、ノードからは正しく解釈されません。
ここで作業スクリプト:
rm ./app/download/!("test1"|"test4");
node.jsでは次のように機能すると思いました:
var spawn = require('child_process').spawn,
PATH = process.argv[1].substr(0, process.argv[1].lastIndexOf('/') + 1), //Get the full path to the directory of the app
arg = [PATH + 'download/!(\"', 'test1', '\"|\"', 'test4', ('\")'],
child = spawn ('rm', arg);
child.stderr.on('data', function(data) {
console.log('stderr:' + data);
});
しかし、私は rm にそれらを異なるファイルとして解釈させます:
stderr:rm: cannot remove '/home/user/app/download("' : No such file or directory
rm cannot remove 'test1' : No such file or directory
...
だから私はこれに引数を変更してみました:
arg = [PATH + 'download/!("' + 'test1' + '"|"' + 'test4' + '")']
しかし、私は得る
stderr:rm: cannot remove '/home/user/app/download/!("test1"|"test2")' : No such file or directory
私はexecを試していますが、生成されたrmがデフォルトでアクティブになっている拡張グロブを解釈しないように見えるので、これが問題だとは思いません...
EDIT:回避策として、ファイルを保持するために開始するパラメータと同じ数でこのコマンドを開始するshスクリプトを実行しようとしています。それは私が望んでいたものではありませんが、今のところ、機能するものが必要です.