|
hai all,
in one of my applications, i have to automate a dos level command.
so i construct the command into an str and execute it using system(str).
but in this case, the console window is getting flashed while the command is being executed.
could any one suggest any other alternative to avoid the display of console.
thanks in advance.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
Hello,
Is it a Windowed application or a console application? Which dos level command are you executing?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
my application is windowed.
actually, there are some Third party command mode tools which should be used in a sequence to perform some operations on wav files and text ifles.
so i wanted to automate them using a single button click.
and each of those tools print some output also, and i have to process and display that output also.
as of now, iam achieving that by redirecting the output to a text file and reading it back.
i would be pleased if you can suggest any easier method also.
bu my immediate problem is to hide or suppress the console window.
if my questin is not clear please let me know. i will try to explain it better.
thank you.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
|
Rajesh R Subramanian wrote: So, you are not working with any DOS commands.
no the sequence of command which i was talking about may also have them.
Yes, i tried to use the create process. but..
CString str;
str.Format("copy database\\*.* %s>>c:\\output.txt",tempfolder);
DeleteFile("output.txt");
STARTUPINFO s;
s.wShowWindow=STARTF_USESHOWWINDOW&&SW_SHOW ;
int ret=CreateProcess(str.GetBuffer(str.GetLength()),NULL,NULL,NULL,NULL,NULL,NULL,NULL,&s,NULL);
there is no result.
what is the mistake here.
|
|
|
|
|
chandu004 wrote: STARTUPINFO s;
s.wShowWindow=STARTF_USESHOWWINDOW&&SW_SHOW ;
s.dwFlags = STARTF_USESHOWWINDOW;
s.wShowWindow = SW_SHOW;
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
no difference still
iam using it this way.
STARTUPINFO s;
s.dwFlags=STARTF_USESHOWWINDOW;
s.wShowWindow=SW_SHOW ;
int ret=CreateProcess(str,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&s,NULL);
here, str contains the command to be executed.
which is working perfectly when i use it with system().
what is the mistake here?
|
|
|
|
|
Try this.
STARTUPINFO si;
PROCESS_INFORMATION pi;
::SecureZeroMemory(&si, sizeof(STARTUPINFO));
::SecureZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW;
::CreateProcess(NULL, str, NULL, NULL, NULL, NULL, NULL, NULL, &si, &pi);
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
securezeromemory undeclared identifier.
this is how the vc++6.0 bangs me. though i included winbase.h.
here i will try to simplify my problem.
say,
str="dir >>c:\\output.txt";
now i want this command to be executed .
can we work in this direction?
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
Use memset instead.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
chandu004 wrote: what is the mistake here.
The "mistake" is that you are not using SHFileOperation() to copy the folder contents.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
thanks for your reply.
can you pleaase explain me how and where to use this function?
thanks in advance.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
chandu004 wrote: can you pleaase explain me how and where to use this function?
See here and here and here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Rajesh R Subramanian wrote:
Redirecting an arbitrary Console's Input/Output[^]
dear rajesh,
this seems to be a perfect source match for my type of requirement.
today iam planning to integrate this feature into my app.
but i found it in vs 2008. i have to use it in vc 6.0.
i will try it and come here if iam facing any problems.
many more thanks again.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
You can hide the console if you use CreateProcess by setting the STARTF_USESHOWWINDOW flag and SW_HIDE in the wShowwindow members of the STARTUPINFO parameter. By I don't think you can run an internal DOS command using CreateProcess.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
«_Superman_» wrote: You can hide the console if you use CreateProcess by setting the STARTF_USESHOWWINDOW flag and SW_HIDE in the wShowwindow members of the STARTUPINFO parameter
oh thank you. i will try it now.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
iam still unable to achieve it.
the return value of CreateProcess is 0.
can you please give some clues?
thank you.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
|
I often use ShellExecuteEx (look it up to know what libraries to link.) This wraps CreateProcess in an easier to use form. I've cut and paste a modified version here.)
To execute a copy; pass "cmd.exe" as the app and "/c command" as the args. Set pDir to the dir where you want the operation to take place. Pass false for show. (The /c tells cmd.exe to execute the command and then exit.)
bool Execute(LPCTSTR pApp, LPCTSTR pArgs, bool show, LPCTSTR pDir)
{
if (!pApp)
{
SetLastError(ERROR_FILE_NOT_FOUND);
return false;
}
SHELLEXECUTEINFO execInfo;
memset(&execInfo, 0, sizeof(execInfo));
execInfo.cbSize = sizeof(execInfo);
execInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
execInfo.lpFile = pApp;
execInfo.lpParameters = pArgs;
execInfo.nShow = show ? SW_SHOW : SW_HIDE;
char path[MAX_PATH];
if (pDir)
{
execInfo.lpDirectory = pDir;
}
else
{
lstrcpyn(path, pApp, MAX_PATH);
if (PathRemoveFileSpec(path))
{
if (path[0])
execInfo.lpDirectory = path;
}
}
if (execInfo.lpDirectory && !DTDirExists(execInfo.lpDirectory))
{
SetLastError(ERROR_PATH_NOT_FOUND);
return false;
}
if (!ShellExecuteEx(&execInfo))
return false;
if (execInfo.hProcess)
CloseHandle(execInfo.hProcess);
return true;
}
modified on Tuesday, August 4, 2009 11:15 AM
|
|
|
|
|
thank you,
i would try your logic also.
thanks again.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
Why does the statement:
printf("This is Raza. \r Who are you? ");
gives the following output.
Who are you?
What effect does the carriage return makes on the text to be printed out?
|
|
|
|
|
i think ,
carriage return(\r) brings the control to the 1st column and linefeed (\n) takes it to the new line.
so u should use \r\n
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
Add a new line to it.
printf("This is Raza. \r\n Who are you? ");
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Someone has down-voted you both. I balanced it... Probably you were suggesting \r\n, while it should have been \n ?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
thank you.
but, AFAIK, while using normal printf, \r\n and \n does the same. but for some consoles like(hyperterminal for example) what i have observed is
using only \n gives the output somehting like
hello
.....world
so i felt using both would be a standard way.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
modified on Monday, June 29, 2009 7:41 AM
|
|
|
|