SHELL creates unicode file, can't read correctly with LINE INPUT - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://staging.qb64phoenix.com/forumdisplay.php?fid=10) +---- Thread: SHELL creates unicode file, can't read correctly with LINE INPUT (/showthread.php?tid=1663) |
SHELL creates unicode file, can't read correctly with LINE INPUT - thesolarcode - 05-05-2023 Hi, I have this snippet to get the number of processor cores. Problem is that the SHELL command produces a unicode text file and LINE INPUT is not able to read the text correctly. Manually converting tmp.txt to an ascii file solves the problem. Question is why is the file created as unicode by default? Can I influence this from within QB64? OS is Win 11. Btw.: I tried also OPEN ... FOR BINARY - doesn't change anything (e.g. LINE INPUT still can't read UNICODE as text): Code: (Select All) returncode% = SHELL("wmic cpu get NumberOfCores >tmp.txt") RE: SHELL creates unicode file, can't read correctly with LINE INPUT - mnrvovrfc - 05-05-2023 Welcome to the forums. You might have to create a second temporary file, after the output of the first "SHELL". I'm not sure where "strings.exe" program is located but you could write a "SHELL" command like this: Code: (Select All) SHELL "strings.exe tmp.txt > tmp2.txt" This "strings.exe" program comes packaged with QB64, somewhere with "g++" compiler, preprocessor, library maker and other utilities. I use Linux regularly and therefore have forgotten a lot of things about Windows, and I have refused to upgrade from Windows10 21H2 on a different computer. The path should be: "(qb64path)/internal/c/c_compiler/bin" or something like that. You could do a search in File Explorer for EXE files into "(qb64path)/internal/c". The "(qb64path)" is a placeholder for the place on your system what is called the "home" directory of QB64. This should be somewhere in your user account, not "Program Files" and even less "Program Files (x86)" if it exists, nor anywhere else on C: drive. It should be something that looks like "C:/Users/(yourname)/qb64" to begin with. EDIT: set your PATH temporarily to "(qb64path)/internal/c/c_compiler/bin" before running your program which should be something like this: Code: (Select All) returncode% = SHELL("wmic cpu get NumberOfCores >tmp2.txt") RE: SHELL creates unicode file, can't read correctly with LINE INPUT - JRace - 05-06-2023 Try piping the output through MORE, which will output plain old text: Code: (Select All) 'JSR sez: changed returncode to _UNSIGNED _INTEGER64, added line to print it & dump it to a file. FWIW: I had to run the WMIC command on the command line to test it. Trying it with the QB64PE (32-bit, hmm) Shell function on my Win7 Pro 64-bit system returns a code and fails to create tmp.txt. (Update: OK, I just tested this program on QB64PE-64, and it is failing with a code of ACBC now. No idea what _that_ means.) (This is my final edit... I pinkie-swear.) FWIW2: https://research.nccgroup.com/2022/03/10/microsoft-announces-the-wmic-command-is-being-retired-long-live-powershell/ RE: SHELL creates unicode file, can't read correctly with LINE INPUT - thesolarcode - 05-06-2023 (05-06-2023, 01:48 AM)JRace Wrote: Try piping the output through MORE, which will output plain old text: Thank you, quite elegant solution. |