"./"和"../"之间有什么区别?

Ron*_*ald 2 node.js nwjs

什么./意思?我假设它用于搜索路径,但我不确定这是否属实.我知道,例如,在C#中,如果我想搜索我可以使用的路径../../file.exe.

目前我想要的是使用以下代码node.js从我的应用程序中运行命令NW.js:

var exec = require('child_process').exec;

exec('node ./server.js', function(error, stdout, stderr) {
    console.log('stdout: ', stdout);
    console.log('stderr: ', stderr);

    if (error !== null) {
        console.log('exec error: ', error);
    }
});
Run Code Online (Sandbox Code Playgroud)

但是,上面的代码不会产生预期的结果.我相信这是因为我不知道如何搜索server.js我想要运行的路径.

orl*_*lla 6

我假设你正在使用某种形式的*NIX.

./是你当前的目录.因此,例如,使用cd ./examplefolder是完全有效的.

../是父目录.因此,例如,您可以使用cd ../上升到目录层次结构中的级别.

~是你的主目录.所以,如果你在~/example/example2/example3,你可以用来cd ~/快速回家.

如果您正在使用nodejs,只需使用该命令node yourfilehere.js将执行它,如果您当前的目录是您要从中启动文件的目录.使用node ../yourfilehere.js作品一样好......不过话又说回来,这样做cd ../node yourfilehere.js.