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;
fname=txtFname->Text;
lblInfo->Enabled = true;
lblInfo->Visible = true;

if(fname=="")
{
lblInfo->Text = "Enter a valid file name";
}
else
{
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.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364955(v=vs.85).aspx

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):
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspx
Topic archived. No new replies allowed.