PHP 中是否有相当于 C# 的 Process.Start 的功能?
在.NET中 Process 类包含几个有用的属性/方法,允许开发人员访问流程相关信息。 PHP 中是否有等效的方法或类?
PHP 中是否有类似 C# 方法“Process.Start()”的等效方法?
In .NET
The Process class contains several useful properties/methods that allow developers to access process relative information.
Is there any equivalent method or class in PHP?Is there any equivalent method in PHP like C# method "Process.Start()"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Evan Plaice 的回答涵盖了一些基础知识,但是 POSIX 系统的很大一部分都是关于管理进程和通信 - 当然,您不在 Unix/Linux 平台上,那么所有这些功能都不可用。如果是,请检查 手册
但它并不尝试解决由 .Net 进程类实现的功能 - 这与 Microsoft 的“程序就是 GUI”的理念密切相关。要使用交互式窗口,您必须查看可作为螺栓连接的 GTK 或 MSWindows 绑定。
Evan Plaice's answer covers some of the basics, however a large part of the POSIX system is all abount managing processes and communication - of course of you're not on a Unix/Linux platform then all this functionality is not available. If you are, then check the manual
However it does not attempt to address the functionality implemented by the .Net process class - which is tied closely to the Microsoft idea that the program is the GUI. For working with interactive windows then you'd have to look at the GTK or MSWindows bindings available as bolt ons.
如果您想访问您创建的进程的标准输入和标准输出,您可以使用:
http://be.php.net/manual/en/function.proc-open.php
If you want access to the stdin and stdout of the process you create, you can use:
http://be.php.net/manual/en/function.proc-open.php
如果(正如您的帖子所暗示的)您在 Windows 上运行,您可以使用 COM 对象(请注意,它在 Linux 上根本不起作用,但它确实为您提供了很多没有它就无法完成的功能)。
运行命令为详细信息。
You can use the COM object if (as your post implies) you're running on Windows (Note it won't work at all on Linux, but it does give you a lot that you couldn't do without it).
The run command is detailed here.
如果您指定了您感兴趣的属性/方法,您可能会得到更多/更好的答案。我不是 C# 开发人员,我也不确定这是否是您所追求的,但是 PHP 手册中有关连接处理的内容是这样的:
您可以使用...
connection_status()
检查连接状态:POSIX 函数(仅在 POSIX 系统下可用)提供一些附加信息。另外,还有一些杂项函数,特别是
sys_getloadavg()
和睡眠功能可能很有用,具体取决于你在寻找什么。有多个程序执行函数,具体为:
exec()
passthru()
proc_open( )
shell_exec()< /code>
- 另请参阅反引号运算符
system()
在 Windows 下您还可以使用 COM 类 打开命令提示符:
另外,如果您愿意为了避免代码注入攻击,不要忘记任何用户提供的输入都应该使用
escapeshellarg()
或escapeshellcmd()
。You probably would get more/better answers if you specified which of properties/methods you are interested about. I'm not a C# developer and I'm also not sure if this is what you're after, but what the PHP Manual has to say about connection handling is this:
You can check the connection status with...
connection_status()
:The POSIX functions (available only under POSIX systems) provide some additional information. Also, some miscellaneous functions, specifically
sys_getloadavg()
and the sleep functions can be useful to do, depending what you're looking for.There are several Program Execution functions, specifically:
exec()
passthru()
proc_open()
shell_exec()
- see also the backtick operatorsystem()
Under Windows you can also use the COM class to open up the command prompt:
Also, if you want to be safe from code injection attacks don't forget that any user supplied input should be escaped with either
escapeshellarg()
orescapeshellcmd()
.1.
参见程序执行函数除外PHP 标准函数中没有方法/类/属性/命名空间的概念。 PHP 本质上是一种过程编程语言,很少有 OOP 结构,并且从上一个主要版本 (5.3) 开始,命名空间支持作为新功能添加。这就是人们批评它为“玩具”语言的原因之一。您可以随时访问所有 PHP 内置函数,没有烦人的命名空间妨碍;),只是要小心名称冲突。
2.
@YSJaitawat 正确答案错误参考。单击此链接可获取PHP 手册中的 exec 函数文档。
注意:此外,如果您要从 C# 迁移到 PHP 并查找信息 PHP 手册 有一些令人惊讶的好信息,包括用户在条目底部提交的评论,人们通常在其中发布用例或标准用途的扩展。由于手册中提供了大量信息,它可能是最容易学习的语言。
1.
See Program execution FunctionsExcept there's no concept of methods/classes/properties/namespaces in the PHP standard functions. PHP is essentially a procedural programming language with few OOP constructs and namespace support being added as a new feature as of the last major release (5.3). It's one of the reasons why people criticise it as a 'toy' language. You can access all of the PHP built-in functions all the time, no pesky namespaces to get in the way ;), just be careful of name collisions.
2.
@YSJaitawat Right answer bad reference.Click this link for the exec function documentation in the PHP manual.
Note: Also, if you're migrating from C# to PHP and looking for info the PHP manual has some surprisingly good info including user-submitted comments at the bottom of the entry where people usually post use-cases or extensions to the standard uses. It's probably the easiest language to learn because of the wealth of info to be found in the manual.
以下代码片段应与“Process.Start()”执行相同的操作
$executable = 'executable process';
exec($可执行文件);
有关流程控制和执行的更多信息,请访问 http://php.net/manual/ en/book.pcntl.php
Following code snippet should do the same as "Process.Start()"
$executable = 'executable process';
exec($executable);
more on process control and execution can be found at http://php.net/manual/en/book.pcntl.php