[英]How to run a C++ Program interactive using external tools in gedit
I'm trying to run my C++ program interactively straight in gedit using external tools.我正在尝试使用外部工具直接在 gedit 中以交互方式运行我的 C++ 程序。
I've already written a Python tool for compiling it, but when using os.system("./program.out")
all input for the program is set to 0 (but it is getting executed right, though).我已经编写了一个 Python 工具来编译它,但是当使用
os.system("./program.out")
时,程序的所有输入都设置为 0(但它正在正确执行)。
Since using Python for executing it interactive would be rather difficult, im looking for another solution.由于使用 Python 交互式执行它会相当困难,我正在寻找另一种解决方案。
#!/usr/bin/env python3
import os
filename = os.getenv("GEDIT_CURRENT_DOCUMENT_NAME")
fout = "%s%s"%(filename[:len(filename)-4], ".out") #
os.system("c++ -o %s %s" % (fout,filename))
os.system("./%s" % fout)
the compiling works flawless, but./program.out also doesn't give the wanted result using bash.编译工作完美无缺,但是./program.out 也没有使用 bash 给出想要的结果。 Any suggestions?
有什么建议么?
I guess i've found an answer.我想我找到了答案。 It may not be the most beautiful solution, but it works.
它可能不是最漂亮的解决方案,但它确实有效。
When defining a tool you can choose the input in a drop-down menu, there is an option for selected text as input.定义工具时,您可以在下拉菜单中选择输入,有一个选择文本作为输入的选项。
So for example, if you have a program that reads 3 variables from stdin, you can add a comment to your code like //1 3 2
, only select the numbers and then run your tool.例如,如果您有一个从标准输入读取 3 个变量的程序,您可以在代码中添加注释,例如
//1 3 2
,仅 select 数字,然后运行您的工具。 These numbers will be used as input in this order, somehow it only works with spaces.这些数字将按此顺序用作输入,不知何故它只适用于空格。
A cruel way of implementing this would be to scan for input calls in the source code and ask for them via zenity in the gedit tool, i guess.我猜,实现这一点的一种残酷方式是扫描源代码中的输入调用,并通过 gedit 工具中的 zenity 请求它们。
And here is another solution:这是另一个解决方案:
I can just use echo 3 2 1 |./program.out
in the tool我可以在工具中使用
echo 3 2 1 |./program.out
this makes everything way more easy这让一切变得更容易
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.