Windows:用于打开控制台并设置路径和工作目录的 USB 密钥的脚本/程序
这个问题背后的目标是创建一个可移植的 Windows 脚本/程序,帮助用户直接从 USB 密钥运行(控制台)程序(但不一定通过自动运行)。因此,双击时,脚本/程序将执行以下操作:
- 启动控制台(
cmd
即可)并给出 DOS 命令提示符, - 将当前目录设置为USB 密钥上的特定目录
WorkingDir
(其中包含各种 [Python] 程序), - 设置路径,以便用户可以运行在另一个 USB 密钥目录中找到的命令(python.exe)(以便用户可以启动各种Python程序
工作目录
)。
整个事情基于 Portable Python,它位于 USB 密钥上。我还希望能够简单地将密钥的内容放在硬盘上并从那里使用它。
我尝试编写一个包含以下命令的文件:
PATH=..\"Portable Python 2.7.2.1\App":%PATH%
cd WorkingDir
cmd
但我不确定如何调用它以便 Windows 运行它(因此我无法查看这些命令是否有效)。
我对 DOS 和 Windows 不太了解,所以任何帮助将不胜感激!
The goal behind this question is to create a portable Windows script/program that would help users run (console) programs directly from a USB key (not necessarily through autorun, though). The script/program would thus do the following when double clicked on:
- Launch a console (
cmd
would do) and give a DOS command prompt, - Have the current directory set to a specific directory
WorkingDir
on the USB key (which contains various [Python] programs), - Set the path so that the user can run a command (python.exe) found in another USB key directory (so that the user can launch various Python programs found in
WorkingDir
).
The whole thing is based on Portable Python, which is on the USB key. I would also like to be able to simply put the contents of the key on a hard drive and use it from there.
I tried to write a file that contains commands like:
PATH=..\"Portable Python 2.7.2.1\App":%PATH%
cd WorkingDir
cmd
but I'm not sure how to call it so that Windows runs it (and I was therefore not able to see whether these command would work).
I don't know much about DOS and Windows, so any help would be much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,在 Windows 中你使用 ;用于分隔路径:)并且您不应该像那样使用 .. 。您可以使用 %CD% 获取当前目录,然后从中导航。并且不要使用引号。另外,您可以将 @ 放在您不希望回显到控制台的任何命令之前。
您可以将其放入 run.bat (这应该可以工作:P):
然后只需双击它,它将按照您想要的方式打开命令提示符。或者您可以添加 autorun.inf 文件以自动打开它。
Actually, in windows you use ; for separating paths :) And you shouldn't use .. like that. You can use %CD% to get current directory and then navigate from it. And don't use quotes. Also, you could put @ before any command that you don't wish to be echoed to the console.
You can put this into run.bat (this should work :P):
And then just double click it and it will open commmand prompt just as you want it. Or maybe you can add autorun.inf file to open it automatically.
您需要创建两个文件:
autorun.inf
autorun.cmd
其中
%~d0
代表命令文件所在的驱动器,即 flash驱动器的盘符 (E:)。现在,我遇到了两个小问题。我的 USB 驱动器上已经有一个隐藏的系统只读 autorun.inf 文件。在编辑它之前,我必须使用以下命令取消对其的保护。
我的第二个问题是 Windows 7 不会从 USB 驱动器自动运行。您必须在资源管理器中右键单击该驱动器并选择“运行 Python 控制台...”
You need to create two files:
autorun.inf
autorun.cmd
The phrase
%~d0
represents the drive the command file resides, namely the flash drive's letter (E:).Now, I encountered two slight hiccups. My USB drive had a hidden, system, readonly autorun.inf file on it already. I had to unprotect it with the following command before I could edit it.
My second hiccup, is that Windows 7 won't autorun from a USB drive. You have to right-click the drive in Explorer and select "Run Python Console..."