在Python中运行外部程序(可执行文件)? [英] Running an outside program (executable) in Python?

查看:374
本文介绍了在Python中运行外部程序(可执行文件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用Python,并且一直在尝试从Python运行外部可执行文件.

I just started working on Python, and I have been trying to run an outside executable from Python.

我有一个用Fortran编写的程序的可执行文件.假设可执行文件的名称为flow.exe.我的可执行文件位于C:\Documents and Settings\flow_model中.我同时尝试了os.system和popen命令,但到目前为止,我无法使其正常工作.以下代码似乎可以打开命令窗口,但不会执行模型.

I have an executable for a program written in Fortran. Let’s say the name for the executable is flow.exe. And my executable is located in C:\Documents and Settings\flow_model. I tried both os.system and popen commands, but so far I couldn't make it work. The following code seems like it opens the command window, but it wouldn't execute the model.

# Import system modules
import sys, string, os, arcgisscripting
os.system("C:/Documents and Settings/flow_model/flow.exe")

我该如何解决?

推荐答案

那些空格确实很麻烦:-(.尝试os.chdir('C:/Documents\ and\ Settings/'),后跟os.systemsubprocess方法或其他方法的相对路径.

Those whitespaces can really be a bother:-(. Try os.chdir('C:/Documents\ and\ Settings/') followed by relative paths for os.system, subprocess methods, or whatever...

如果尽力避免绕过路径中的空白栏不断失败,那么我的下一个最佳建议是避免在关键路径中留空.您能否建立一个无空白的目录,在其中复制关键的.exe文件,然后尝试那个?那些破坏惨重的空间对您的健康绝对必要吗??

If best-effort attempts to bypass the whitespaces-in-path hurdle keep failing, then my next best suggestion is to avoid having blanks in your crucial paths. Couldn't you make a blanks-less directory, copy the crucial .exe file there, and try that? Are those havoc-wrecking space absolutely essential to your well-being...?

这篇关于在Python中运行外部程序(可执行文件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆