How does Windows hook up cmd.exe?
来源:互联网 发布:电脑盲打软件 编辑:程序博客网 时间:2024/06/06 02:30
原文: http://discuss.joelonsoftware.com/default.asp?design.4.332503.5
When Windows invokes an application that uses the "console" subsystem, it launches cmd.exe which is used to display the application's output. Text typed into cmd.exe is also transmitted to the application, as expected.
Two questions:
a) How does Windows decide which program is supposed to handle console applications? Is this just a registry key?
b) How does Windows do this standard input/standard output piping? It can't be using popen() because cmd.exe is exhibiting more functionality than popen() allows (read/write to a co-process).
When Windows invokes an application that uses the "console" subsystem, it launches cmd.exe which is used to display the application's output. Text typed into cmd.exe is also transmitted to the application, as expected.
Two questions:
a) How does Windows decide which program is supposed to handle console applications? Is this just a registry key?
b) How does Windows do this standard input/standard output piping? It can't be using popen() because cmd.exe is exhibiting more functionality than popen() allows (read/write to a co-process).
Michael B
Sunday, April 16, 2006
Sunday, April 16, 2006
Windows executables have a flag in their PE header indicating whether they are console or GUI applications: http://www.windowsitlibrary.com/Content/356/11/1.html .
GinG
Sunday, April 16, 2006
Sunday, April 16, 2006
"When Windows invokes an application that uses the "console" subsystem, it launches cmd.exe which is used to display the application's output. Text typed into cmd.exe is also transmitted to the application, as expected."
This not correct. Are you thinking of a batch file that was invoked by the shell? Batch files -( .bat/.cmd files ) are associated with cmd.exe through COMSPEC registry key.
(HKLM/System/CurrentControlSet/Control/Session Manager/Environment".
When you execute a program directly ( createprocess ) you dont have a shell. The clearest evidence of this is that the ordinary dir and pipe operations dont work.
a - the explorer decides which program based on the filename extension.
b - if you arent running in cmd.exe, you dont get ordinary piping like ( |, >, < ). But stdin, stdout, stderr are part of the win32 process specification. The CreateProcess call accepts (via startup info ) handles for stdin, stdout and stderr. So its up to the program that launched this program. They are just ordinary windows handles. Could be a file, named pipe, whatever.
This not correct. Are you thinking of a batch file that was invoked by the shell? Batch files -( .bat/.cmd files ) are associated with cmd.exe through COMSPEC registry key.
(HKLM/System/CurrentControlSet/Control/Session Manager/Environment".
When you execute a program directly ( createprocess ) you dont have a shell. The clearest evidence of this is that the ordinary dir and pipe operations dont work.
a - the explorer decides which program based on the filename extension.
b - if you arent running in cmd.exe, you dont get ordinary piping like ( |, >, < ). But stdin, stdout, stderr are part of the win32 process specification. The CreateProcess call accepts (via startup info ) handles for stdin, stdout and stderr. So its up to the program that launched this program. They are just ordinary windows handles. Could be a file, named pipe, whatever.
B
Sunday, April 16, 2006
Sunday, April 16, 2006
"How does Windows do this standard input/standard output piping?"
CreateProcess() can accept three file handles (stdin, stdout, stderr). The father process creates anonymous pipes, initializes a STARTUPINFO with the pipes' handles, and calls CreateProcess() to launch the child:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createprocess.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/startupinfo_str.asp
Have a look on http://support.microsoft.com/default.aspx?scid=kb;en-us;190351 for an example.
CreateProcess() can accept three file handles (stdin, stdout, stderr). The father process creates anonymous pipes, initializes a STARTUPINFO with the pipes' handles, and calls CreateProcess() to launch the child:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createprocess.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/startupinfo_str.asp
Have a look on http://support.microsoft.com/default.aspx?scid=kb;en-us;190351 for an example.
GinG
Sunday, April 16, 2006
Sunday, April 16, 2006
Ohhhhh.
All is clear, now.
All is clear, now.
Michael B
Sunday, April 16, 2006
Sunday, April 16, 2006
There is also the issue of the Windows Console Device and related API calls. This doesn't necessarily have a thing to do with standard I/O streams, and thus often can't be redirected.
This is why some people get frustrated with custom shells or even trying to control a spawned "Console EXE" via anonymous pipes. Examples include the FTP.EXE that comes with Windows (at least the 2000/XP versions), EDIT.EXE, and many others such as several networking-related commands.
This is why some people get frustrated with custom shells or even trying to control a spawned "Console EXE" via anonymous pipes. Examples include the FTP.EXE that comes with Windows (at least the 2000/XP versions), EDIT.EXE, and many others such as several networking-related commands.
Lutz
Monday, April 17, 2006
Monday, April 17, 2006
This topic is archived. No further replies will be accepted.
- How does Windows hook up cmd.exe?
- windows系统 ---cmd.exe
- windows系统 --cmd.exe
- How does Xen's Guest Domain wake up..?
- How does Windows Embedded CE 6.0 Start
- How does Windows Embedded CE 6.0 Start?
- C:\WINDOWS\System32\cmd.exe”返回
- windows cmd.exe 学习(1)
- windows批处理 打开exe后关闭cmd
- cmd.exe
- cmd.exe
- How to Hook Up a VS.NET 2005 Solution With CruiseControl.NET in a Few Minutes
- How to stop cmd.exe run in administrator mode cmd.exe总是以管理员账户运行的解决办法
- HOW TO: Set a Windows Hook in Visual C# .NET
- HOW TO: Set a Windows Hook in Visual C# .NET
- How to Set Up Your Own Home Seedbox (in Windows)
- How to Set Up Chinese Characters on Windows 7
- vs2010的qt项目错误 “cmd.exe”已退出 qt File does not exist
- 关系数据库的查询优化策略(二)
- gridview全选
- [转] 解析oracle的ROWNUM
- window.createPopup()创建菜单
- 毕业设计框架配置完毕开始研究Birt Runtime
- How does Windows hook up cmd.exe?
- linux下的I/O重定向
- 如何优化SQL Server数据库查询(三)
- ref out 的用法小结
- MinGW 编译 GDIPlus 程序
- 读Windows核心编程 - 7
- 消息队列(Message Queue)简介及其使用
- C/C++程序员应聘常见面试题深入剖析
- 爱情哲学