How do I send output from the terminal to a text file in Visual Studio Code with the proper encoding? - character-encoding

I'm having issues sending output containing Unicode box-drawing characters to a text file.
The string ┌───top───┐ prints to the terminal fine using the print command. It also renders properly if I open and write directly to a file in my code.
However, if I pipe the terminal output into a text file using
<run command> > out.txt, I get the result
ΓöîΓöÇΓöÇΓöÇtopΓöÇΓöÇΓöÇΓöÉ
Everything else prints fine, but why doesn't it handle certain Unicode characters?
Is there a quick fix for this?

Related

Read Files Using Lua by Directory Using Command Prompt

I was trying to read a .txt file using lua in command prompt, I'm using 'Lua For Windows' but in the way I tried it's not working, it don't give me any error, it don't return anything, not even 'nil'.
I tried this:
file = io.open("C:\Users\user\Desktop\a.txt", "r") --(and my user's name)
io.input(file)
print(io.read())
io.close(file)
The backslash is an escape character in Lua quoted strings.
Try "C:\\Users\\user\\Desktop\\a.txt".
Or avoid the issue using long strings: [[C:\Users\user\Desktop\a.txt]].

Android ESC/POS protocol printing in Cyrillic

I bought a no-name Android ESC/POS printer, it support Bluetooth. I need help in printing Cyrillic symbols in Windows-1251 charset. What I do first:
\x1B\x40 (ESC # to initialize printer)
\xD5\xD3\xC9\n (the text that I need to print, standard Windows-1251 symbols, but it shows me some abracadabra :))
I should say, that the charset is set to Windows-1251 on the printer (by the exe tool that comes with it)
Also I tried command \x1B\x74\x49 (it sets the Windows-1251 manually, but there is no effect). Any ideas what we can do with it? Thank you all.
You can try my app that print cyrillic text: https://play.google.com/store/apps/details?id=pe.diegoveloper.printerserverapp
Configure your ESC/POS printers on 'Quick Printer' and print from your app.
I tried many variants and after this manual end up with this character code page settings { 27, 116, 9 }
outputStream.write(new byte [] { 27, 116, 9 });
outputStream.write("Привет Мир".getBytes("cp866"));
outputStream.write(PrinterCommands.LF);
Try to convert your text to cp866.
And set code page in printer via ESC/POS command into 17.
With Universal Cyriclic decoder you can find your source encoding/decoding.
Enter in decoded field your output text. For example 袩褉懈胁械褌.
Select source encoding UTF-8.
Then find your wanted decoding charset by selecting field "display as".

Print special characters in console

In my console (XP), the following line echo "áéíóú" in a utf-8 encoded file prints this:
├í├®├¡├│├║
Im not sure if this is something i have to handle in nim.
I am not sure if it works on Windows XP, but if you have Windows 8.1 your Nim code should be fine provided that in your console you change code page to UTF-8 with the following command:
chcp 65001
You need Lucida Console font too.
Keep in mind that in the Output window of Aporia editor you don't need to change anything in order to see the correct characters.

Produce a download file from CGI in Lua

I am writing a simple CGI program in lua. What I want to achieve is produce a response from CGI which enables a file to be downloaded from the browser. But I just can't print the data. I have no idea what's going on here. Here is the code below:
print("Content-Type: text/html; charset=UTF-8")
print("Content-Length:" .. sys.getenv("CONTENT_LENGTH"))
print("Content-Disposition:",'attachment;filename="backup.tar.gz"\n')
print("Content-Type:application/x-tar-gz\n\n")
file=io.popen("some command")
output = file:read('*a')
print(output)
--file:close()
The problem is I just can't print the output whose content is binary. I can see the type of output is string.
What is the problem? Please give some hints about it. Thank you.
ADD : I have no idea about this and Where is the issue. Let me put more info about the command I want run. But I don't think that matters.
Actually, I work in openwrt, the web server uhttpd. (No LuCI here)
The command is:sysupgrade -b - 2>/dev/null. This command is used to backup the config file. I want to write a CGI to download the backup file from the web.
But I can not print the output to the server. Even in the terminal(in lua IDE) I cannot print out the output except one or two messy code. But I can write the output to a file in terminal. Maybe it has some relationship with the content of out.
When I print the content line by line, it prints some, but not all of it. After I download the file. I can't open it.
print("Content-Disposition:",'attachment;filename="backup.tar.gz"\n')
print("Content-Type:application/x-tar-gz\n\n")
I think you have way too many new lines. First of all, you can newline in Content-Disposition and this is in addition to the newline that print adds, which ends the headers and makes Content-Type a part of the payload (which breaks the content). You also have two newlines in Content-Type where you only need one (as one is added by the print command).
I think something like this should work:
local file = io.popen("some command")
local output = file:read('*a')
file:close()
print("Content-Type: text/html; charset=UTF-8")
print("Content-Length: " .. #output)
print("Content-Disposition: " .. 'attachment;filename="backup.tar.gz"')
print("Content-Type: application/x-tar-gz\r\n")
print(output)

How to print an excel document from command line with PRINT command in MSDOS

Im trying to print an excel document through a default printer configured from command prompt using PRINT command as shown below:
C:>print c:\printdocs\test1.xls
by typing above and pressing enter a line saying 'C:\test1.xls is currently being printed'
is getting displayed but the excel document is not sent for default printer for printing. Please help me with this, where iam going wrong.
print.exe is designed to print a text file, and nothing else. In fact, if you type print /? from a command prompt, it tells you that in the first line of the text:
C:\>print /?
Prints a text file.
PRINT [/D:device] [[drive:][path]filename[...]]
/D:device Specifies a print device.
So the answer to your question is that you can't print an Excel file via print from the command line, because an .XLS file isn't a text file.

Resources