cmderdev / cmder

Lovely console emulator package for Windows
https://cmder.app
MIT License
25.81k stars 2.02k forks source link

Spurious "/title" in initial command line #2820

Closed duncairn closed 1 year ago

duncairn commented 1 year ago

Version Information

Cmder version: 1.2.31
Operating system: Windows 7x64 SP1

Cmder Edition

Cmder Full (with Git)

Description of the issue

I have a task which initially calls a setup .bat file.

-cur_console:d:G:\ESP32\idf4.2\esp-idf cmd /k ""G:\ESP32\dev.espressif\idf_cmd_init.bat" "G:\Python\" "G:\Tools\Git\cmd\""

Within that file is the following line: if "%~2"=="" (

If I call Cmdr with that task as the argument (that is, this is the initial task) the .bat fails with "The syntax of the command is incorrect" at that line. The displayed output from the .bat is: G:\ESP32\idf4.2\esp-idf>if "G:\Tools\Git\cmd\"" /title "Cmder"=="" (

If I start Cmdr with the default task, and then start this task in a new tab, it works perfectly and the output of that line is: G:\ESP32\idf4.2\esp-idf>if "G:\Tools\Git\cmd\" == "" (

If I switch Cmder.exe for a previous version (V1.3.14, which is what I used before) there is no problem.

How to reproduce

No response

Additional context

No response

Checklist

DRSDavidSoft commented 1 year ago

@duncairn Can you please attach your ConEmu.xml or user_ConEmu.xml in Cmder so we can investigate? Firstly please check if the file that you attach contains the ESP32 IDF task, thanks.

duncairn commented 1 year ago

ConEmu.xml attached. ConEmu.zip

chrisant996 commented 1 year ago

What is esp-idf in the -cur_console:d:G:\ESP32\idf4.2\esp-idf cmd /k ""G:\ESP32\dev.espressif\idf_cmd_init.bat" "G:\Python" "G:\Tools\Git\cmd""?

My guess would be that esp-idf is parsing the part ""G:\ESP32\dev.espressif\idf_cmd_init.bat" "G:\Python" "G:\Tools\Git\cmd"" differently than CMD does. Specifically, the "" might be getting turned into " (or removed) before the cmd /k is launched. I suspect that because that would indeed cause the final "" to end up being considered part of %2.

_UPDATE: never mind -- the -cur_console:d: flag specifies a directory, so esp-idf is part of a directory name, not a program._

duncairn commented 1 year ago

Yes :) Just to confirm, I changed the folder to 'esp_idf' but it didn't fix it.

chrisant996 commented 1 year ago

deleted

duncairn commented 1 year ago

I would have put this down to cmd parsing the quotes a bit funnily, but there are two things that caused me to think it's not that:

  1. The presence of '/title "Cmder"' on the command line - presumably that's aimed at ConEmu and shouldn't make it to the final command.
  2. It only occurs with the new Cmder. exe - using the older version is fine.

I changed the command line to call a simple test.bat instead:

-cur_console:d:G:\ESP32\idf4.2\esp-idf cmd /k ""R:test.bat" "G:\Python\" "G:\Tools\Git\cmd\""

The contents of test.bat are: echo 0: %0, 1: %1, 2: %2, 3: %3, 4: %4

The result of the new version Cmder.exe: 0: "R:test.bat", 1: "G:\Python\", 2: "G:\Tools\Git\cmd\"" /title "Cmder, 3: , 4:

And the old version Cmder.exe: 0: "R:test.bat", 1: "G:\Python\", 2: "G:\Tools\Git\cmd\", 3: , 4:

That, to me, implies that something has changed in Cmder.exe to cause this. Could it have been a side effect of https://github.com/cmderdev/cmder/pull/2752#issue-1409914347

chrisant996 commented 1 year ago

@DRSDavidSoft this is a bug in the Cmder launcher:

Here is the code:

CmderLauncher.cpp

@@  -427,14  +428,19  @@
    if (!streqi(cmderTask.c_str(), L""))
    {
        swprintf_s(args, L"%s /run {%s}", args, cmderTask.c_str());
    }

+   if (!streqi(cmderTitle.c_str(), L""))
+   {
+       swprintf_s(args, L"%s /title \"%s\"", args, cmderTitle.c_str());
+   }
+
    if (cfgRoot.length() != 0)
    {
        swprintf_s(args, L"%s  -loadcfgfile \"%s\"", args, userConEmuCfgPath);
    }

    if (!streqi(cmderConEmuArgs.c_str(), L""))
    {
        swprintf_s(args, L"%s %s", args, cmderConEmuArgs.c_str());
    }

But the ConEmu documentation states about the /run switch that "This must be the last used switch (excepting -new_console and -cur_console)."

So the Cmder launcher is appending /title and -loadcfgfile in an incorrect position in the command line.

Depending on what cmderConEmuArgs.c_str() can contain, it may be getting appended in an incorrect position as well.

duncairn commented 1 year ago

Thanks very much, @chrisant996

DRSDavidSoft commented 1 year ago

@chrisant996 Hi there, thanks for the investigation and the fix, this issue has been closed by #2806. Sorry I've been super busy these couple of weeks, will be back for the other fixes soon.