【发布时间】:2018-08-02 09:52:24
【问题描述】:
我正在为 Inkscape 开发一个插件。一些版本:
- Inkscape v0.92.3
- Windows 10 版本 1803(内部版本 17134.165)
- 显式安装 Python 3.7
- MonoDevelop 版本 7.7 预览版 (7.7) 以下额外版本
安装地点:
- Inkscape:C:\Program Files\Inkscape
- 扩展名:C:\Program Files\Inkscape\share\extensions
- 包含:
myplugin.inx、myplugin.py、MyPlugin.exe
- 包含:
出于开发原因,我制作了一个插件,该插件可以按当前预期工作。
最重要的是,当我从 MonoDevelop 或构建的 exe 本身运行它时,它会运行(无论是在同一位置生成的 .dll 等,还是仅将 exe 复制到不同的位置) )。
我使用SugarPillStudio's python script(稍加编辑的版本)来运行 .exe 文件。但是,当我通过调用扩展程序运行该 python 脚本时,不会启动 .exe。 Inkscape 闪烁显示“MyPlugin 正在启动...”的消息,并在打开时立即关闭。
我知道 python 脚本可以工作,因为我让它将调试行打印到我桌面上的 .log 文件中。我知道 .exe 不会启动,因为我还让它在同一个 .log 文件中写入行,这是调用 main() 时的第一件事。当我(成功)运行 .exe 时,它会打印到文件中,而当我运行扩展程序时,它不会。
这让我相信 python 脚本在调用 .exe 时存在问题。有什么帮助吗?
Python 脚本:
#!/usr/bin/env python
'''
sugarpillstudios.com/wp/?p=142
'''
import os, sys, subprocess, datetime
f=open("C:\Users\Diamundo\Documents\plugin.log", "a+")
f.write("[PYT] %s Python script called at: %s.\n" % (datetime.datetime.now().isoformat(), os.getcwd() ) )
argv = []
for arg in sys.argv[:]:
if arg.startswith("--executable="):
executable = arg.split("=")[1]
else:
argv.append(arg)
argv[0] = executable
f.write("[PYT] %s %s\n" % ( datetime.datetime.now().isoformat(), executable ) )
process = subprocess.Popen(argv,shell=False,stdout=subprocess.PIPE)
print process.communicate()[0]
插件.inx:
<inkscape-extension>
<name>MyPlugin</name>
<id>name.space.plugin.main</id>
<param name="executable" type="string" gui-hidden="true">MyPlugin.exe</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu _name="MyPlugin"/>
</effects-menu>
</effect>
<script>
<command reldir="extensions" interpreter="python">myplugin.py</command>
</script>
</inkscape-extension>
额外的 Monodevelop 版本:
Runtime:
Microsoft .NET 4.0.30319.42000
GTK+ 2.24.26 (Light theme)
GTK# 2.12.45
NuGet
Version: 4.3.1.4445
.NET Core
Runtime: C:\Program Files\dotnet\dotnet.exe
Runtime Versions:
2.0.9
2.0.5
SDK: C:\Program Files\dotnet\sdk\2.1.202\Sdks
SDK Versions:
2.1.202
2.1.4
MSBuild SDKs: Not installed
【问题讨论】:
标签: python subprocess inkscape