PHP 中是否有相当于 C# 的 Process.Start 的功能?

发布于 2024-09-04 12:01:34 字数 147 浏览 5 评论 0原文

  1. 在.NET中 Process 类包含几个有用的属性/方法,允许开发人员访问流程相关信息。 PHP 中是否有等效的方法或类?

  2. PHP 中是否有类似 C# 方法“Process.Start()”的等效方法?

  1. 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?

  2. Is there any equivalent method in PHP like C# method "Process.Start()"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

旧伤慢歌 2024-09-11 12:01:35

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.

┾廆蒐ゝ 2024-09-11 12:01:35

如果您想访问您创建的进程的标准输入和标准输出,您可以使用:

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

诗笺 2024-09-11 12:01:35

如果(正如您的帖子所暗示的)您在 Windows 上运行,您可以使用 COM 对象(请注意,它在 Linux 上根本不起作用,但它确实为您提供了很多没有它就无法完成的功能)。

$com = new COM('WScript.Shell');
$com->run('Path/To/Shell/Program', 0, false);

运行命令为详细信息

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).

$com = new COM('WScript.Shell');
$com->run('Path/To/Shell/Program', 0, false);

The run command is detailed here.

逆流 2024-09-11 12:01:35

在 .NET 中,Process 类包含几个有用的属性/方法,
允许开发者访问进程
相关信息。你有吗
PHP 中的等效方法或类。

如果您指定了您感兴趣的属性/方法,您可能会得到更多/更好的答案。我不是 C# 开发人员,我也不确定这是否是您所追求的,但是 PHP 手册中有关连接处理的内容是这样的:

当PHP脚本正常运行时
NORMAL 状态处于活动状态。如果
远程客户端断开ABORTED的连接
状态标志已打开。一个遥控器
客户端断开连接通常是由于
用户按下“停止”按钮。如果
PHP 施加的时间限制(参见
set_time_limit()) 被命中,TIMEOUT
状态标志已打开。

您可以使用... connection_status() 检查连接状态:

switch (connection_status())
{
    case CONNECTION_NORMAL:
        // ...
    break;

    case CONNECTION_ABORTED:
        // ...
    break;

    case CONNECTION_TIMEOUT:
        // ...
    break;
}

POSIX 函数(仅在 POSIX 系统下可用)提供一些附加信息。另外,还有一些杂项函数,特别是sys_getloadavg() 和睡眠功能可能很有用,具体取决于你在寻找什么。

PHP 中有任何等效方法,例如 C# 方法“Process.Start()”。

有多个程序执行函数,具体为:

在 Windows 下您还可以使用 COM 类 打开命令提示符:

$cmd = new COM('WScript.Shell');

另外,如果您愿意为了避免代码注入攻击,不要忘记任何用户提供的输入都应该使用 escapeshellarg()escapeshellcmd()

In .NET The Process class contains several useful properties/methods that
allow developers to access process
relative information. Have you any
equivalent method or class in PHP.

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:

When a PHP script is running normally
the NORMAL state, is active. If the
remote client disconnects the ABORTED
state flag is turned on. A remote
client disconnect is usually caused by
the user hitting his STOP button. If
the PHP-imposed time limit (see
set_time_limit()) is hit, the TIMEOUT
state flag is turned on.

You can check the connection status with... connection_status():

switch (connection_status())
{
    case CONNECTION_NORMAL:
        // ...
    break;

    case CONNECTION_ABORTED:
        // ...
    break;

    case CONNECTION_TIMEOUT:
        // ...
    break;
}

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.

Have any equivalent method in PHP like C# method "Process.Start()".

There are several Program Execution functions, specifically:

Under Windows you can also use the COM class to open up the command prompt:

$cmd = new COM('WScript.Shell');

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() or escapeshellcmd().

抠脚大汉 2024-09-11 12:01:34

1.参见程序执行函数

除外PHP 标准函数中没有方法/类/属性/命名空间的概念。 PHP 本质上是一种过程编程语言,很少有 OOP 结构,并且从上一个主要版本 (5.3) 开始,命名空间支持作为功能添加。这就是人们批评它为“玩具”语言的原因之一。您可以随时访问所有 PHP 内置函数,没有烦人的命名空间妨碍;),只是要小心名称冲突。

2. @YSJaitawat 正确答案错误参考。

单击此链接可获取PHP 手册中的 exec 函数文档

注意:此外,如果您要从 C# 迁移到 PHP 并查找信息 PHP 手册 有一些令人惊讶的好信息,包括用户在条目底部提交的评论,人们通常在其中发布用例或标准用途的扩展。由于手册中提供了大量信息,它可能是最容易学习的语言。

1. See Program execution Functions

Except 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.

⊕婉儿 2024-09-11 12:01:34

以下代码片段应与“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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文