0

我有一个 django web,它在某些操作上使用以下命令在服务器上调用 .exe:

proc = subprocess.Popen([r'C:/.../django/project/app/program.exe', 'arg1', 'arg2', ..], stdout=subprocess.PIPE)
s = proc.stdout.read()
proc.wait()

问题是 program.exe 又必须在服务器上打开一些文件。此文件由代码(在 c++ 中)使用相对路径调用,并存储在 .exe 所在的同一文件夹中。当我从 IDE 或终端运行 program.exe 时,它​​就像一个魅力,但不是在服务器上时。

我用 C++ 做了一个简单的程序,并将其放在与 program.exe 相同的文件夹中,以了解在服务器上运行 program.exe 时的当前路径是什么:

#define GetCurrentDir _getcwd
int main(int argc, char* argv[]{
    char cCurrentPath[FILENAME_MAX];
    GetCurrentDir(cCurrentPath, sizeof(cCurrentPath));
    std::cout << cCurrentPath << std::endl;
}

在返回 C:/.../django/project/app 的状态下,它返回 C:/.../django/project。我知道我可以设置文件相对于 cCurrentPath 的路径,但是有没有其他方法可以通过更改服务器配置来做到这一点?

我在 Windows 上使用 2 个不同的服务器,apache 和 django 开发服务器。

4

0 回答 0