2

我的网页上传了一个文件。目前,它将该文件放在一个由 cron 作业轮询的目录中。如果该文件存在,则 bash 脚本将作用于该文件。我讨厌我正在投票的事实。上传可能每周发生一次,但用户希望在几分钟内从他们的文件中看到结果,所以我最终每 5 分钟轮询一次。

因此,我不想轮询,而是想在上传完成后调用脚本。如何让我的网页启动 bash 脚本。网页是用 JSP 编码的。

4

2 回答 2

3

So long as you haven't got a SecurityManager set, you can use Runtime.exec to call an executable program. In particular you can run /bin/bash (or whatever path it is to your shell). Note the -c option for shells.

As LFSR points out, this is the sort of thing likely to be full of security flaws.

于 2009-01-21T23:06:37.713 回答
-2

Why don't you do this from your app? It won't be very hard to implement an FTP client in Java. Surely there are open/free libraries to accomplish this somewhere. I don't believe this script does anything that you can't do in Java. A message driven bean with the FTP code should be enough. Your server is not FTP? Well, installing FTP isn't that hard either.

于 2009-01-21T23:37:05.000 回答