Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在linux上脚本找不到文件,但在windows上它可以找到_Javascript_Linux_File_Ubuntu_Ubuntu 16.04 - Fatal编程技术网

Javascript 在linux上脚本找不到文件,但在windows上它可以找到

Javascript 在linux上脚本找不到文件,但在windows上它可以找到,javascript,linux,file,ubuntu,ubuntu-16.04,Javascript,Linux,File,Ubuntu,Ubuntu 16.04,我有一个脚本需要一个client_secret.json文件,在windows上,scipt可以找到它,没有问题,但是当我把它放在我的ubuntu服务器上时,它给出了一个错误,它找不到路径。 为什么呢? mmy代码如下所示: fs.readFile('./client_secret.json', (err, content) => { if (err) return console.log('Error loading client secret file:', err);

我有一个脚本需要一个client_secret.json文件,在windows上,scipt可以找到它,没有问题,但是当我把它放在我的ubuntu服务器上时,它给出了一个错误,它找不到路径。 为什么呢? mmy代码如下所示:

fs.readFile('./client_secret.json', (err, content) => {
    if (err) return console.log('Error loading client secret file:', err);
    // Authorize a client with credentials, then call the Google Sheets API.
    authorize(JSON.parse(content), methodname);
  });
正如我所说,它在linux上运行到错误分支上,但在windows上运行得非常好。

这可以: s、 readFile(path.join(_dirname,'client_secret.json'))
别忘了npm i path

您可能正在使用不同的工作目录运行。您是想读取脚本旁边的文件吗,如
fs.readFile(path.join(u dirname,'client_secret.json')),…
?您可能希望检查文件名是否包含大写字母。windows中的文件名区分大小写,而linux/Unix中的文件名区分大小写。所有文件都是小写的。该文件与我以前使用的脚本位于同一文件夹中,但没有“/”,但具有相同的效果