我正在尝试编写一个 sublime 函数,它将获取当前文件并在 ConEmu 的新 shell 中运行它,我在转义 \t 时遇到了一些问题
当我有一条看起来像的路径时
c:\ps\test.ps1
t 被丢弃了,我试图做一些事情来逃避它,但没有任何运气。
这是崇高的功能
class ConemuPstestCommand(sublime_plugin.TextCommand):
def run(self, edit):
if self.view.file_name():
if self.view.is_dirty():
self.view.run_command("save")
folder = path.dirname(self.view.file_name())
testFile = path.join(folder, "test.ps1")
if(not (path.exists(testFile))):
testFile = path.join(path.split(folder)[0],"test.ps1")
if(path.exists(testFile)):
testFile = testFile + "\n"
print(testFile)
testFile = re.sub(r'\t', r'\\t', testFile)
#testFile = testFile.translate(str.maketrans({"\t": r"\\\t","\\": r"\\"}))
print(testFile)
subprocess.call([CONEMUC, "-GUIMACRO:0","Task(""{Shells::PowerShell}"")"],startupinfo=si)
#subprocess.call([CONEMUC, "-GUIMACRO:0","Recreate(0,0,0)"],startupinfo=si)
subprocess.call([CONEMUC, "-GUIMACRO:0", "PASTE", "2", testFile], startupinfo=si)
基本上的想法是,如果您在 powershell 模块中按 F6,它将在该文件夹中运行 test.ps1。基于这两个 print(testFile),sublime 控制台中的输出看起来是正确的,当它进入 powershell 时,测试中的 t 丢失(奇怪的是 \ 仍然存在)
真正奇怪的是,如果我注释掉 Task()(新的 powershell 控制台)行,它会正确地将其复制到当前控制台(相同的 conemu 任务类型)
我正在运行版本 150513 [64] 和 sublime 3 (3083)
作为一个简单的测试,我从一个 conemu 控制台运行了这段 python 代码
import re,subprocess
CONEMUC = "C:\\Program Files\\ConEmu\\ConEmu\\ConEmuC64.exe"
si = subprocess.STARTUPINFO()
si.dwFlags = subprocess.STARTF_USESHOWWINDOW
si.wShowWindow = subprocess.SW_HIDE
subprocess.call([CONEMUC, "-GUIMACRO:0","Task(""{Shells::PowerShell}"");context;print(""test"")"],startupinfo=si)
这将启动控制台正常,但它不打印文本
Python 版本也是 Win32 上的 Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:16:31) [MSC v.1600 64 bit (AMD64)]
一个更简单的测试,我启动了一个 cmd shell 并运行了这个命令
ConEmuC.exe -guimacro task("{Shells::cmd}");context;print("test")
它将报告OK;OK;OK 新的 shell 被打开并在我运行它的控制台中打印测试。所以看起来上下文并没有真正做它应该做的事情?
我刚刚尝试了另一个简单的测试
ConEmuC.exe -guimacro Create(0,0);context;print("test")
这次它工作正常。似乎 Task() 和 Context 不想一起工作?
似乎不太确定这是 conemu 正在做的事情还是事情的崇高/python 方面。有什么想法吗?
谢谢