I am trying to get the free disk space from all the logical drives available on the computer using batch and VB.net. Using "wmic" i get the required output and then using VB convert the 'bytes' value to MB/GB/KB but the problem is i am unable to get the VB script to read the text output from 'wmic' command. Below is the 'wmic' code.
wmic LogicalDisk Where DriveType="3" Get DeviceID,FreeSpace > Diskspace.txt
Below the vb code to read the 'diskspace.txt' file
Set objFSO = CreateObject ("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile ("diskspace.txt",1)
Contents = objFile.Readall
objFile.close
The point being is there a simpler way to get available free space from all the logical drives on the system ? or i am doing something wrong in my above code.
I also tried "/format:csv" parameter in wmic, but not able to get it to read in VB.
Found the Solution !!
The output of a WMI is on unicode format and needs to be converted to ASCII format for VB to be able to read it.
To convert use the TYPE command (batch) as below
TYPE diskspace.txt > NEWdiskspace.txt
Related
I'm supplying a c++ .dll to a user who is writing an installer via an NSIS script. Using System.dll, the user can call my .dll as such:
System::Call 'my.dll::GetJson(v) t .r0'
DetailPrint $0
The return value of GetJson() gets stored in $0. This is all working correctly, though GetJson() may return a json blob whose length is > 8192, in which case the value stored in $0 gets truncated.
I looked at trying to increase NSIS_MAX_STRLEN by building NSIS myself using scons, as mentioned here: https://nsis.sourceforge.io/Special_Builds
scons NSIS_MAX_STRLEN=16384 PREFIX=C:\somewhere install-compiler install-stubs
However, after doing this, the NSIS-compiled .exes crashed upon running. It seems like 8192 may be some kind of memory limitation.
Is there any way around this for me? For example, would it be possible to call
System::Call 'mydll::GetJson(v) t .r0'
But instead of the return value being stored in $0, have it be split into chunks? Perhaps it's possible to write the contents of GetJson() to a file first, and then NSIS can read that and split it?
Any help is appreciated. Thank you.
If the user needs to edit a very long string you basically have two options:
Use the system plug-in to fill a text field on a nsDialogs custom page. You can't use the registers to store the string, you need to use ...func()p.r0 to get the raw address of the string from your plug-in and use Sendmesage to fill the text field. To save you need to allocate memory, get the text with SendMessage and write it to a file and finally free the memory.
The other option is to create the custom page with your custom plug-in.
I'm trying to create a Fortran code for defining processor id. I can write the processor id into a text file. The text file pid2.txt is created but I can not read it in Fortran. While I open the text file in notepad or NotePad++ everything seems OK! In Fortran when I opening the text file it shows unknown parameter. Can any body help me with this problem?
The content of text file is
ProcessorId
BFEBFBFF00010676
The sample code is as below:
program get_PID
implicit none
character(200) :: line
call system('wmic cpu get ProcessorId >pid2.txt ' )
open (1,file='pid2.txt')
read (1,*) line
read (1,*) line
CLOSE (1)
end program
Do you have any advice?
The issue in your case is the encoding of the ouput from wmic. Windows uses UTF-16 as default. Fortran cannot handle this encoding yet. Referring to the help of Intel Fortran, only UTF-8 is supported as described here.
Therefore you have to change the encoding of the output to ANSI and/or your local codepage. This can be done by piping the result of wmic through the more command as described on SO superuser site under combine-batch-wmic-ansi-unicode-output-formatting.
Please change your system call as follows:
call system('wmic cpu get ProcessorId | more >pid2.txt ' )
You'll get the processor ID information in your code now, as expected.
Hope it helps.
How I can to read any gdsii file in python,or Convert gds file into text format using gds2text script?
If you can use a C/C++ compiler you might consider using gds2gdt and gdt2gds to read and/or write GDSII using any language/shell of your choice. GDSII is a stream of records each of which is represented in a single line of compact GDT format text. For instance:
p{10 w1.2 xy(41.2 17.1 41.2 33.9)}
is a two-point path on layer 10 with a width of 1.2. you can run these programs externally or call them within your program similar to reading/writing a text file.
https://sourceforge.net/projects/gds2/
there. I am trying to pass a Text Field contents into a database call (mysql). When I look at the field that gets returned from Text->getvalue.(funct) call - I simply do not get the text that was entered into the field - via any of the UTF functions in WXWidgets. I have tried the following:
wxChar buffer = ((wxTextCtrl*)FindWindow(wxID_TITLE))->GetValue().mb_str(wxConvUTF8);
//GooglyGook for whole thing
wxChar buffer = ((wxTextCtrl*)FindWindow(wxID_TITLE))->GetValue().mb_str();
//NULL it fails completely
wxChar buffer = ((wxTextCtrl*)FindWindow(wxID_TITLE))->GetValue().ToUTF8();
//More GOoblygook
wxChar buffer = ((wxTextCtrl*)FindWindow(wxID_TITLE))->GetValue().utf8_str();
//More Gooblygook
message.Printf(_T("The title saved as wxCharBuffer =%s"),buffer.data());
wxMessageBox(message,_("Rivendell"), wxICON_ERROR|wxOK);
The message box is how I am trying to display what is in the wxChar buffer,
but I am running in debug so I can simply look at it during the run and confirm that it is incorrect. Please note that I have tried these wxChar buffer lines one at a time separately (not like they are listed here). Just wanted to show things I had tried.
What is the correct way to do this? The type of characters I am attempting to save in the db looks like:"check Todd 1 乞: 乞丐 qǐgài, 乞求 qǐqiú, 乞讨 qǐtǎo."
The gooblygook output looks like Chineese characters etc.. even in the English part of the field (Check Todd)...
Anyone who has an idea of how to do this please let me know. Thanks...
Tb
I appreciate the help provided, and after trying some things I found an answer.
The correct way to do this seems to be the following: Put the TextCtrl field into a wxString using wx_str(). Then put the wxString into a wxCHarBuffer via toUTF8() function. Then use the data() function of the wxCHarBuffer to pass a char pointer.
Part of my problem stemmed from trying to display what was in those fields via Visual Studio Debugger, and/or wxMessage boxes - so sometimes my conversions were wrong (as noted by the previous poster).
I was able to set the wxString (s) to Unicode characters and have it be handled correctly by the mysql call (i.e. Call would crash before). The chk_title variable returned seems to be correctly encoded into UTF8 and escaped.
Thanks.
i'm studing on file operations (c++) and i came to a deadlock
i can read datas from a file but i want to put some rules. for example my .txt file is:
<play
**guitar = "false"
**clarinet = "true"
>
<clairnet
**color = "black"
**type = "g"
>
i want to reach clarinet.color and may be change later. i wrote too long codes, i can reach it now. (reading the file character by character and searching for "clarinet" first, when it found it, it start to search color from the "clarinet" line. when it sees color start to search for "=" then gets all the line since = and strtok by ""s.)
it's hard for the hardware and me :')
and the main problem is changing the value. i copy all file except the value, change the value and write all to the file again.
i need to save all datas like a class to the file, like using mysql with php.
how can i do it?
Use serialization. For example: http://www.boost.org/doc/libs/1_58_0/libs/serialization/doc/index.html