我们可以在Java-Cucumber项目中使用Python代码吗

发布于 2025-02-12 05:45:00 字数 157 浏览 0 评论 0 原文

我必须将巨大的划界文件转换为XLSX文件。 Python使此任务变得容易。因此,我可以在Cucumber-Java框架中为此转换编写一个Python脚本。 此Python代码只会将文件转换为XLSX,然后将其用于Cucumber-Java框架的其余文件。 如果这是正确的方法,请指定如何实现这一目标?

I have to convert huge delimited file into xlsx file. Python makes this task easy. So can I write one python script for this conversion in my cucumber-java framework.
This python code will just convert file to xlsx then this file will be use for rest of cucumber-java framework.
If this is correct approach, please specify how to achieve this?

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

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

发布评论

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

评论(1

属性 2025-02-19 05:45:00

简短答案:您可以使用过程类。我包括了一个超链接,因此您可以熟悉此API。在Java中运行过程的一般形式如下:

Process p = Runtime.getRuntime().exec(...);

exec 方法内部,您需要为需要运行的可执行过程提供详细信息。产生过程的另一种方法是使用 ProcessBuilder 类。对我来说,这是一个更清晰的方法:

ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command(...);
processBuilder.start(); // don't forget to start the process

可以在单个字符串中表示命令,也可以在逗号分隔的参数列表中表示。例如:

processBuilder.command("hello.exe", "/c", "dir C:/Users/hector");

或者

processBuilder.command("c:/Users/hector/hello.bat");

对您来说,这看起来可能是这样的:

ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("c:/Users/user13987365/convertAndSaveXLSX.py");
processBuilder.start(); // don't forget to start the process

一旦保存XLSX,Cucumber方案就应该能够转到该文件位置并以任何目的使用XLSX文件。当然,为了能够运行Python脚本,您需要安装它并从任何目录中调用Python命令,您需要将Python放在路径中。

The short answer: You can run (execute) any process from a Java application using the Process class. I included a hyperlink so you can get familiarized with this API. The general form for running a process in Java is as follows:

Process p = Runtime.getRuntime().exec(...);

Inside the exec method, you need to provide the details for the executable process you need to run. Another way to spawn a Process is by using the ProcessBuilder class. To me, this is a much clearer approach:

ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command(...);
processBuilder.start(); // don't forget to start the process

A command can be represented in a single String, or a comma-separated list of arguments. For example:

processBuilder.command("hello.exe", "/c", "dir C:/Users/hector");

or

processBuilder.command("c:/Users/hector/hello.bat");

For you, this could look something like this:

ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("c:/Users/user13987365/convertAndSaveXLSX.py");
processBuilder.start(); // don't forget to start the process

Once you save your XLSX, your Cucumber scenario should be able to go to that file location and use the XLSX file for whichever purpose. OF COURSE, in order to be able to run Python scripts, you need to have it installed and to invoke the python command from any directory, you need to have Python in your path.

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