函数适用于相对路径输入,但不适用于绝对路径输入

发布于 2024-10-11 20:32:52 字数 1030 浏览 9 评论 0原文

存在一个属于软件包 (MRICro) 一部分的功能,它被称为“dcm2nii”。

当使用相对路径作为输出目录时,该函数运行得很好。

但是,当使用完全相同文件夹的绝对路径时,该功能就会崩溃。

示例(绝对路径):

dcm2nii -o /net/user1/project_name/Data/2011_01_10_SVD1/Processed/3_fMRI_rest E2538S3I00*

示例(相对路径):

dcm2nii -o ../Processed/3_fMRI_rest E2538S3I00*

使用输出文件夹的绝对路径时出现的示例错误消息(最后一行提示无法创建输出文件):

Validating 52 potential DICOM images.
Found 52 DICOM images.
Converting 52/52  2
E2538S3I0001.MR.dcm->20110110_112950E2538S3I0001MRFPSD1F29OCT2010RCs003a1001.nii
GZip 20110110_112950E2538S3I0001MRFPSD1F29OCT2010RCs003a1001.nii
unable to create /net/user1/project_name/Data/2011_01_10_SVD1/Processed/3_fMRI_rest/20110110_112950E2538S3I0001MRFPSD1F29OCT2010RCs003a1001.nii.gz

不知道是否是这个问题造成的对我来说,在 Linux/bash 中做错了什么,或者由于该函数实际上有错误。

但是,任何意见都会受到赞赏。

在更一般的层面上,我正在寻找任何可预见的原因来解释为什么函数能够使用相对文件夹路径而不是绝对文件夹路径(前提是它们解析到同一位置)。

编辑: pwd 给出: /net/user1/project_name/Data/2011_01_10_SVD1/3_fMRI_rest

There exists a function that is part of a software package (MRICro), and it is called 'dcm2nii.'

When a relative path is used as the output directory, the function works perfectly well.

But, when the absolute path to the exact same folder is used, the function breaks down.

Example (absolute path):

dcm2nii -o /net/user1/project_name/Data/2011_01_10_SVD1/Processed/3_fMRI_rest E2538S3I00*

Example (relative path):

dcm2nii -o ../Processed/3_fMRI_rest E2538S3I00*

Sample error message that occurs when using the absolute path for the output folder (the last line suggests that the output file can not be created):

Validating 52 potential DICOM images.
Found 52 DICOM images.
Converting 52/52  2
E2538S3I0001.MR.dcm->20110110_112950E2538S3I0001MRFPSD1F29OCT2010RCs003a1001.nii
GZip 20110110_112950E2538S3I0001MRFPSD1F29OCT2010RCs003a1001.nii
unable to create /net/user1/project_name/Data/2011_01_10_SVD1/Processed/3_fMRI_rest/20110110_112950E2538S3I0001MRFPSD1F29OCT2010RCs003a1001.nii.gz

I do not know if this problem is due to me doing something wrong in Linux/bash or due to the function actually having a mistake.

But, any input is appreciated.

On a more general level, I am looking for any foreseeable reason for why a function would be able to use a relative folder path and not an absolute one (provided that they resolve to the same location).

EDIT: pwd gives:
/net/user1/project_name/Data/2011_01_10_SVD1/3_fMRI_rest

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

牵你的手,一向走下去 2024-10-18 20:32:52

在我们告诉您问题的原因之前,您确实必须向我们展示代码,但是您描述的行为是可能的

这是一个不良实践的示例,但请考虑以下内容

#!/bin/bash
....
current_dir = $(pwd)
out_dir = $1
cd ${somewhere}
..... do stuff
#no we want to come back to create the output dir
mkdir ${current_dir}/$out_dir

you would really have to show us the code before we can tell you what the cause of the problem is, however the behaviour you described is possible

This is an example of poor practice but consider the following

#!/bin/bash
....
current_dir = $(pwd)
out_dir = $1
cd ${somewhere}
..... do stuff
#no we want to come back to create the output dir
mkdir ${current_dir}/$out_dir
烟─花易冷 2024-10-18 20:32:52

这似乎是某种错误..我遇到了同样的问题。如果我尝试对主文件夹中的数据执行此命令,我会收到相同的错误。

但是,如果我将数据移动到不涉及任何扩展的路径,即“/tmp/data”,则程序执行正常。

This appears to be a bug of some kind.. I am experiencing the same issue. If I try to execute this command on data in my home folder, I get the same error.

However, if I move my data to a path that doesn't involve any expansion, i.e. ''/tmp/data'', the program executes fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文