Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd 里面exe路径带空格无法运行 #37

Closed
fcying opened this issue Dec 17, 2018 · 10 comments
Closed

cmd 里面exe路径带空格无法运行 #37

fcying opened this issue Dec 17, 2018 · 10 comments

Comments

@fcying
Copy link

fcying commented Dec 17, 2018

无法运行

"path": "",
"cmd": "D:\\Program Files\\AutoHotkey\\AutoHotkeyU64.exe",

包了 " 号也不行

"cmd": "\"D:\\Program Files\\AutoHotkey\\AutoHotkeyU64.exe\"",

path 里面带空格的正常

"path": "D:\\Program Files\\AutoHotkey",
"cmd": "AutoHotkeyU64.exe",
@rexdf
Copy link
Owner

rexdf commented Dec 17, 2018

本来设置path的用途就是用来下面那种用法的。

这个错误貌似比较诡异。亏你能测出来,不过暂时不想修,其实可以算作特性的那种。

真实原因是,关于working_directory的,当它会空是它会继承自path。如果path已经为空,那么working_directory就真的为空了。

下面这两种都可以正常运行:

"path": "",
"cmd": "D:\\Program Files\\AutoHotkey\\AutoHotkeyU64.exe",
"working_directory": "D:\\Program Files\\AutoHotkey",

以及

"path": "D:\\Program Files\\AutoHotkey",
"cmd": "D:\\Program Files\\AutoHotkey\\AutoHotkeyU64.exe",
"working_directory": "",

修复方法也是有的,尝试在path为空时,从cmd提取目录。

但是这里有一个麻烦之处在于cmd里面会含有参数, 比如这种"cmd": "cmd.exe /k \"cd /d d:\ && start java.exe\""

@rexdf rexdf closed this as completed in c554a56 Dec 17, 2018
rexdf added a commit that referenced this issue Dec 17, 2018
@rexdf
Copy link
Owner

rexdf commented Dec 17, 2018

可以测试下这个新版本

@fcying
Copy link
Author

fcying commented Dec 18, 2018

新版本, 只设置cmd(带绝对路径) 另外2个不设置可以跑了, 不过带上cmd 带上配置文件后就不行了.
想实现的功能是 程序安装在机器上(绝对路径), 配置文件在u盘上(相对路径)

最后发现, 不需要让path为空. 设path为上一级目录就能正常工作了

    "path": "..",
    "cmd": "D:\\Program Files\\AutoHotkey\\AutoHotkeyU64.exe autohotkey\\script\\main.ahk",
    "working_directory": "",

@rexdf
Copy link
Owner

rexdf commented Dec 18, 2018

感觉上,这只是因为D:\\Program Files\\AutoHotkeyautohotkey\\script\\有一个同名autohotkey的巧合而已。

而且带配置的目录识别基本上无解的,具有二义性。至于是否支持引号,我也不知道。o(╯□╰)o

比如 D:\\A log Path\\a.exe cmd.exe 到底表示什么,到底是D:\\A log Path\\a.exe带参数,还是一个名为a.exe cmd.exe的文件。 这种问题我交给Windows自己判断了,我完全没处理这个问题的细节,直接看Windows返回啥就用啥。

感觉你用出了不得了的用法了^_^

点提交前,又看了下你的回复。配置文件相对目录,实际上是相对的working_directory,本次修改后改成从cmd提取了,所以working_directory变成绝对目录了。也许让working_directory识别"working_directory": ".",的时候补上CommandTrayHost.exe所在目录比较好?

"path": "",
"cmd": "D:\\Program Files\\AutoHotkey\\AutoHotkeyU64.exe autohotkey\\script\\main.ahk",
"working_directory": ".",

这种感觉比你上面的要稍微直观一点儿。晚上我再看看怎么改成这个逻辑。

感觉要在注释里面加几个你提出来的这几种特殊用法了o(╯□╰)o

@rexdf
Copy link
Owner

rexdf commented Dec 18, 2018

可以试下新的working_directory符号>.

如果有空,参考这个wiki,暂时我还不敢发布正式版,还需要补内置的文档。

https:/rexdf/CommandTrayHost/wiki/path-cmd-working_directory的隐式转换规则

下载地址

https:/rexdf/CommandTrayHost/releases/tag/2.2-b442

@fcying
Copy link
Author

fcying commented Dec 19, 2018

试了下最新的. working_directory 设成> 后工作一直不正常(设了后 带不带配置都无法启动)
如果没理解错的话, working_directory设了后, 应该是配置文件是相对于working_directory来设置的吧?

正常

            "path": "..",
            "cmd": "D:\\Program Files\\AutoHotkey\\AutoHotkeyU64.exe autohotkey\\script\\main.ahk",
            "working_directory": "",
            "path": "",
            "cmd": "D:\\Program Files\\AutoHotkey\\AutoHotkeyU64.exe",
            "working_directory": "",
            "path": "",
            "cmd": "D:\\Program Files\\AutoHotkey\\AutoHotkeyU64.exe",
            "working_directory": ".",

不正常 autohotkey createprocess failed

            "path": "..",
            "cmd": "D:\\Program Files\\AutoHotkey\\AutoHotkeyU64.exe autohotkey\\script\\main.ahk",
            "working_directory": ">",
            "path": "",
            "cmd": "D:\\Program Files\\AutoHotkey\\AutoHotkeyU64.exe",
            "working_directory": ">",
            "path": "",
            "cmd": "D:\\Program Files\\AutoHotkey\\AutoHotkeyU64.exe autohotkey\\script\\main.ahk",
            "working_directory": ".",

rexdf added a commit that referenced this issue Dec 19, 2018
rexdf added a commit that referenced this issue Dec 19, 2018
@rexdf
Copy link
Owner

rexdf commented Dec 19, 2018

>=写成了>导致单独的>号没法识别 o(╯□╰)o 我先发布一个正式版试试

@fcying
Copy link
Author

fcying commented Dec 20, 2018

最新版本工作正常

            "path": "",
            "cmd": "D:\\Program Files\\AutoHotkey\\AutoHotkeyU64.exe ..\\autohotkey\\script\\main.ahk",
            "working_directory": ">",
            "path": "D:\\Program Files\\AutoHotkey",
            "cmd": "AutoHotkeyU64.exe ..\\autohotkey\\script\\main.ahk",
            "working_directory": ">",

@rexdf
Copy link
Owner

rexdf commented Dec 20, 2018

        "path": "D:\\Program Files\\AutoHotkey",
        "cmd": "AutoHotkeyU64.exe main.ahk",
        "working_directory": ">..\\autohotkey\\script",

理论上也应该正常才对

@fcying
Copy link
Author

fcying commented Dec 21, 2018

        "path": "D:\\Program Files\\AutoHotkey",
        "cmd": "AutoHotkeyU64.exe main.ahk",
        "working_directory": ">..\\autohotkey\\script",

理论上也应该正常才对

试了下, 这种也可以正常工作

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants