拖放批处理文件相当于在Linux中 [英] Drag and drop batch file equivalent in Linux

查看:157
本文介绍了拖放批处理文件相当于在Linux中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前能够通过一个.bat文件通过我的python脚本来运行文件。此批处理文件的内容很简单:

I am currently able to run files through my python script via a .bat file. The contents of this batch file is simply:

C:\Python26\python.exe mypythonfile.py %1
pause

我可以拖放各种文件到.bat文件和python脚本将执行,利用被丢弃的文件作为参数...使用sys.argv中

I can drag and drop various files onto the .bat file and the python script will execute, using the dropped file as the argument...using sys.argv

这是罚款的窗口。但我想现在要做的是什么,是做Linux中的等价物。

This is fine for windows. But what I want to do now, is do the equivalent in Linux.

任何帮助将大大AP preciated。

Any help would be greatly appreciated.

推荐答案

你的脚本在的Bourne兼容的shell (如相当于庆典破折号的zsh 和大多数其他炮弹你发现在Linux上)将是:

the equivalent of your script on a bourne compatible shell (like bash, dash, zsh and most other shells you ever find on linux) would be:

#!/bin/sh
python /path/to/my/pythonfile.py $1
read

在实践中,这是不是真的需要,至于拖丁基下降,你会在桌面上创建一个应用程序快捷方式,仅仅包含蟒蛇/path/to/my/pythonfile.py $ 1 作为应用程序的字符串。并用它做。

in practice this is not really needed, as for drag-n-drop you would create an application "shortcut" on your desktop that simply contains python /path/to/my/pythonfile.py $1 as the application string. and be done with it.

真正干净的解决方案,甚至会的家当#的/ usr / bin中/ Python的添加到您的.py文件的顶部,使其可执行 - !所以你可以直接运行它作为

the really clean solution would even add the shebang #!/usr/bin/python to the top of your .py-file and make it executable - so you can run it directly as

/path/to/my/pythonfile.py $1

您的GUI(图标,在那里你可以放下的东西)整合脚本,取决于你实际使用的桌面环境。

integrating the script with your GUI (icon, where you can drop things at), is depending on the actual desktop environment you use.

创建一个新的启动器(如的右键单击的面板上,增加新元素,选择的启动的;然后右击新建的启动图标,点击添加新对象,给它一个名称,并在CMDLINE场添加

create a new launcher (e.g. right-click on a panel, "add new element", choose Starter; then right click on the newly created Starter-Icon, click on "add new object", give it a name and in the cmdline-field add

/full/path/to/my/script.sh %U

%U 将与任何你拖放图标被替换。

the %U will be replaced with whatever you drop on the icon.

这篇关于拖放批处理文件相当于在Linux中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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