Help me with this program

Recently, I came across a useful command for finding the file size in cmd. I just wanted to implement it from c++ windows forms. So I created a form and added a textbox,button and a label. The textbox takes the file name as input and is stored in fname variable. The label displays any errors or the file size.

The click event of the button contains this code:
const char* str;
const char* val;
lblInfo->Enabled = true;
lblInfo->Visible = true;

lblInfo->Text = "Enter a valid file name";
cmnd=L"for %I in ("+fname+") do @echo %~zI";
str = (const char*) (Marshal::StringToHGlobalAnsi(cmnd)).ToPointer();
lblInfo->Text = L"Size of file is: "+system(str)+" bytes";
The function system returning the exit code and not the size of the file.
How can I get the output of a command in cmd?

I must get the output of the command and display it in the label "lblInfo"..

Thanks in advance
To get file size use win32api GetFileSize() directly. I do not know C++/CLI equivalent to this as you do not use C or C++ programming language.

If you really want to use output from cmd.exe then you must use pipes to capture standard output of your spawned child process. An example can be seen here (again this is in C language, not C++/CLI that you are using):
Topic archived. No new replies allowed.