Navigation Menu

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

Output of ConEmuC disappears when assigned to a variable #1415

Closed
Maximus5 opened this issue Jul 31, 2015 · 6 comments
Closed

Output of ConEmuC disappears when assigned to a variable #1415

Maximus5 opened this issue Jul 31, 2015 · 6 comments

Comments

@Maximus5
Copy link
Owner

Originally reported on Google Code with ID 1415

OS version: Win7 SP1 x64
ConEmu version: 131225 [64]
Far version: n/a

When the output of ConEmuC is assigned to a variable, the variable is empty. At first
I thought this was caused by the absence of a newline sequence at the end of the output
(like the behaviour of traditional Unix text utilities), but, as the following example
shows, powershell doesn't care about that.

PS> (get-command printf).definition
C:\Program Files (x86)\GnuWin32\bin\printf.exe
PS> printf '%s' Yes
YesPS> $x = printf '%s' Yes; "$($x.length) |$x|"
3 |Yes|
PS> conemuc /guimacro isConEmu
YesPS> $x = conemuc /guimacro isConEmu; "$($x.length) |$x|"
0 ||
PS> "|$(conemuc /guimacro isConEmu)|"
||
PS>

As you can see, no problem when printf writes a string without newline terminator to
stdout, but the output of ConEmuC has vanished. It's not assigned to variable x, nor
does it appear in the terminal window. What's happening here?

Reported by mb97531 on 2013-12-30 11:04:55

@Maximus5
Copy link
Owner Author

Result of macro execution is Unicode. So, it is "printed" to console with WriteConsoleW,
which PowerShell ignores.

If you need to check "IsConemu", there is an easier way
> ConEmuC /IsConEmu
> $LASTEXITCODE

Reported by ConEmu.Maximus5 on 2013-12-30 11:27:34

@Maximus5
Copy link
Owner Author

The (undocumented) /IsConEmu option is indeed an easier way. I checked out trunk to
‘discover’ other hidden options.

But there are some other macro functions I'd like to be able to use. I'm not familiar
with windows API, but according to Microsoft's Console Reference, WriteFile can be
used when output is redirected. Perhaps, something like,

    if (!GetConsoleMode(hOut, &dwWritten))
        WriteFileW(hOut, asBuffer, nAllLen, &dwWritten, 0);
    else
        WriteConsoleW(hOut, asBuffer, nAllLen, &dwWritten, 0);

in _wprintf() in ConEmuCD\ConsoleMain.cpp ?

Reported by mb97531 on 2014-01-01 09:45:20

@Maximus5
Copy link
Owner Author

This was already fixed in my "daily" branch.
But this was not so easy as you think :D
There is NO "WriteFileW" function in WinAPI. Only ANSI (or MultiByte) strings may be
written during redirection. With taking into account of current console CodePage of
course...

Reported by ConEmu.Maximus5 on 2014-01-01 12:47:55

@Maximus5
Copy link
Owner Author

https://code.google.com/p/conemu-maximus5/wiki/Whats_New#Build_120708

Reported by ConEmu.Maximus5 on 2014-01-01 12:51:31

@Maximus5
Copy link
Owner Author

140104

Reported by ConEmu.Maximus5 on 2014-01-05 03:56:15

  • Status changed: Fixed

@Maximus5
Copy link
Owner Author

Thank you for fixing this, and updating pConsoleHelp and the ConEmuC wiki.


Reported by mb97531 on 2014-01-05 11:48:32

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

1 participant