Home > Software engineering >  Using the popen call console application, how to hide bullet box?
Using the popen call console application, how to hide bullet box?

Time:10-11

Everyone a great god, and I use popen exe calls to a third party, and access to its output, but the execution of the black box will pop up the console, could you tell me how to hide?

CodePudding user response:

 WinExec (CMD/c dir "c: \ \ *. * & gt; D: \ \ cfiles. TXT ", SW_HIDE); 

CodePudding user response:

Hello, I'm using the popen, is there a way to not play the console window?

CodePudding user response:

Is there a way to? grateful

CodePudding user response:

CreateDesktop?

CodePudding user response:

Fyi:
 # pragma comment (lib, "user32") 
#include
# include & lt; string.h>
#include
Int main () {
SECURITY_ATTRIBUTES sa={0};
STARTUPINFO si={0};
PROCESS_INFORMATION PI={0};
HANDLE hPipeOutputRead=NULL;
HANDLE hPipeOutputWrite=NULL;
HANDLE hPipeInputRead=NULL;
HANDLE hPipeInputWrite=NULL;
BOOL bTest=0;
DWORD dwNumberOfBytesRead=0;
DWORD dwNumberOfBytesWrite=0;
CHAR szMsg [100].
CHAR szBuffer [256].

Sa. NLength=sizeof (sa);
Sa. BInheritHandle=TRUE;
Sa. The lpSecurityDescriptor=NULL;

//Create pipe for standard output redirection.
The CreatePipe (& amp; HPipeOutputRead,//read handle
& HPipeOutputWrite,//write handle
& Sa,//security attributes
0//number of bytes reserved for pipe - 0, the default
);

//Create pipe for standard input redirection.
The CreatePipe (& amp; HPipeInputRead,//read handle
& HPipeInputWrite,//write handle
& Sa,//security attributes
0//number of bytes reserved for pipe - 0, the default
);

//Make the child process use hPipeOutputWrite as standard out,
//and make sure it does not show on screen.
Si. Cb=sizeof (si);
Si. DwFlags=STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
Si. WShowWindow=SW_HIDE;
Si. HStdInput=hPipeInputRead;
Si. HStdOutput=hPipeOutputWrite;
Si. HStdError=hPipeOutputWrite;

CreateProcess (
NULL, "CMD. Exe,"
NULL, NULL,
TRUE, 0,
NULL, NULL,
& Si, & amp; PI);

//Now that handles have had inherited, close it to be safe.
//You don 't want to read or write to them accidentally.
The CloseHandle (hPipeOutputWrite);
The CloseHandle (hPipeInputRead);

//Now test to capture the DOS application output by reading
//hPipeOutputRead. Could also write the to DOS application
//standard input by writing to hPipeInputWrite.
Sprintf (szMsg, "ver \ n");
WriteFile (
HPipeInputWrite,//handle of the write end of our pipe
& SzMsg,//address of buffer that send data
Strlen (szMsg),//the number of bytes to write
& DwNumberOfBytesWrite,//the address of the number of bytes read
NULL//non - overlapped.
);

While (TRUE)
{
BTest=ReadFile (
HPipeOutputRead,//handle of the read end of our pipe
& SzBuffer,//the address of the buffer that receives the data
256,//the number of bytes to read
& DwNumberOfBytesRead,//the address of the number of bytes read
NULL//non - overlapped.
);

if (! BTest) {
Sprintf (szMsg, "pipe. Error # % d reading", GetLastError ());
Printf (" % s ", szMsg);
break;
}

//do something with the data.
SzBuffer [dwNumberOfBytesRead]=0;//null terminate
Printf (" % s ", szBuffer);
If (' & gt; '==szBuffer] [dwNumberOfBytesRead - 1) break;
}

Sprintf (szMsg, "CHCP \ nexit \ n");
WriteFile (
HPipeInputWrite,//handle of the write end of our pipe
& SzMsg,//address of buffer that send data
Strlen (szMsg),//the number of bytes to write
& DwNumberOfBytesWrite,//the address of the number of bytes read
NULL//non - overlapped.
);

While (TRUE)
{
BTest=ReadFile (
HPipeOutputRead,//handle of the read end of our pipe
& SzBuffer,//the address of the buffer that receives the data
256,//the number of bytes to read
& DwNumberOfBytesRead,//the address of the number of bytes read
NULL//non - overlapped.
);

if (! BTest) {
Sprintf (szMsg, "pipe. Error # % d reading", GetLastError ());
Printf (" % s ", szMsg);
break;
}

//do something with the data.
SzBuffer [dwNumberOfBytesRead]=0;//null terminate
Printf (" % s ", szBuffer);
}

//Wait for CONSPAWN to finish.
WaitForSingleObject (PI) hProcess, INFINITE);

//Close all remaining handles
The CloseHandle (PI. HProcess);
The CloseHandle (hPipeOutputRead);
The CloseHandle (hPipeInputWrite);

return 0;
}
//C: \ test> nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related