简体   繁体   English

将参数传递给新产生的终端

[英]Passing arguments to a newly spawned terminal

I am trying to automate some task at work. 我正在尝试使工作中的某些任务自动化。 One of them is to run some aliases, one of which spawns a new terminal, an XTerm from a bash terminal. 其中之一是运行一些别名,其中之一会生成一个新的终端,即来自bash终端的XTerm。 Now after spawning this terminal, I would need to provide some more commands into this new terminal. 现在,在生成该终端之后,我需要向该新终端中提供更多命令。

How can this be achieved. 如何做到这一点。 One method that I can think of is using expect scripts to handle those tasks. 我能想到的一种方法是使用Expect脚本来处理这些任务。 Would this work? 这行得通吗? if not, are there any methods to run commands on the new terminal. 如果没有,是否有任何方法可以在新终端上运行命令。

Edit: 编辑:

Within the script I found this.... 在脚本中,我发现了这个...。

 execcmd="xterm -sb -sl 5000 -T "'`/usr/bin/hostname -s`.$LOADL_STEP_CLASS'" -e $path run_interactive $@

I think this is the one that spawns the new xterm out.. I need to run some commands on this script and then, get whatever it spits out on screen, looking for a particular string like for example "priority-level:" , rest would be simple regex doing the job for me, but I want to automate the interactions with this new xterm that spawned. 我认为这是生成新xterm的代码。我需要在此脚本上运行一些命令,然后将其显示在屏幕上,寻找特定的字符串,例如“ priority-level:”,其余将很简单的正则表达式为我完成工作,但是我想与产生的这个新xterm自动进行交互。

PS: I have no straight forward way of passing arguments to this terminal while spawning, without messing up with scripts that many other people are using. PS:我没有直接的方法在生成时将参数传递给此终端,而又不会弄乱许多其他人正在使用的脚本。 so I cannot modify the original alias, maybe write a wrapper around it somehow. 因此我无法修改原始别名,也许以某种方式围绕它编写包装。

Isn't that what the -e *args* flag to xterm is for? 这不是xterm的-e *args*标志的作用吗? It's going to run whatever you feed it there, so if you modify that argument so that the script or command it invokes also does the extra step you need, you're done. 它会在此处输入的任何内容运行,因此,如果您修改该参数,以便它调用的脚本或命令也执行您需要的额外步骤,就可以完成。

An alternative is to make the xterm shell a login shell so that your shell startup scripts are invoked, but that will have the side effect of invoking them for every login shell, which might be be suitable in your environment. 一种替代方法是使xterm Shell成为登录Shell,以便调用您的Shell启动脚本,但是这样做的副作用是为每个登录Shell调用它们,这可能适合您的环境。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM