本地服务器上的 PHP exec 命令 - 为什么这不起作用?

发布于 2024-12-28 14:45:30 字数 480 浏览 1 评论 0原文

我想要在本地服务器上为自己构建的 Web 应用程序进行剪贴板访问,我想出了这个:

首先是从另一个文件读取的批处理文件:

clip < %1

然后在我的 PHP 文件中:

exec("mybatch.cmd $file_with_text_to_be_copied");

不需要返回变量,只需直接执行...

任何日志中都没有错误,但它就是不起作用。

考虑到剪贴板的安全性,我对它不起作用并不感到惊讶,但我不明白为什么 - chrome 或 Apache 或任何人如何知道我在做什么?

我什至尝试了一些我在网上读到的关于将 Apache 服务帐户更改为由另一个帐户用户运行的内容(我认为这是系统帐户 - 不记得了 - 但它是我在网上读到的任何内容) 但没有改变......

顺便说一句,Windows 机器 - 以防万一被错过。

I wanted clipboard access for a web app that I built for my own use on my local server, and I came up with this:

First a batch file that reads from another file:

clip < %1

and then in my PHP file:

exec("mybatch.cmd $file_with_text_to_be_copied");

no return variable needed, just straight execute...

No error in any log, but it just doesn't work.

I'm not surprised it doesn't work, given the security around clipboards, but I can't figure out why - how does chrome or Apache or whoever even know whats I'm doing?

I even tried something I read online about changing the Apache service account to being run by another account user (I think it was the system account - can't remember - but it was whatever I read online)
but no change...

Windows machine by the way - just in case that got missed.

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

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

发布评论

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

评论(3

み零 2025-01-04 14:45:30

剪贴板是会话的属性,因此您在桌面会话上使用 ctrl-c 和朋友使用的剪贴板与您的网络服务器看到的剪贴板不同。

因此,如果没有任何帮助应用程序(在您的会话中运行),这是不可能的。

顺便说一句:这很好,这是不可能的。想一想,直到你相信为止。

The clipboard is a property of the session, so the clipboard you use with ctrl-c and friends on your desktop session is not the same, as the clipboard your webserver sees.

So without any helper app (running in your session) this is not possible.

BTW: It is good, this is not possible. Think over that, until you believe it.

岁月打碎记忆 2025-01-04 14:45:30

据我所知你不能这样访问剪贴板。我建议制作一个简单的 JS 脚本来实际读取剪贴板,并对后端函数进行简单的 AJAX 调用(将剪贴板作为参数传递),然后用它执行您需要的任何操作。

但是,某些浏览器可能会限制通过 JS 访问剪贴板。

As far as I know you cannot access the clipboard like that. I would suggest making a simple JS script that actually reads your clipboard and the make a simple AJAX call to a back-end function (passing in the clipboard as a parameter) and then do whatever you need with it.

However, some browsers might limit access to the clipboard via JS.

夜无邪 2025-01-04 14:45:30

您是否尝试过使用 system() 函数?使用系统显示输出。然后你就可以找到解决可能出现错误的方法。

系统功能示例:

$response = system('ls -al', $return);
echo $response . "<br />" . $return;

Did you try to use the system() function ? use system to display the output. Then you can find a way to solve possible errors.

Example with system function:

$response = system('ls -al', $return);
echo $response . "<br />" . $return;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文