如何退出 Perl 脚本执行期间运行的 vi 会话?

发布于 2025-01-07 09:48:55 字数 621 浏览 0 评论 0原文

我必须做一些工作。运行每个作业后,它会对内容运行 vi。写入并退出后(通常我这样做 :wq!),这些数据会在数据库中更新。由于此类工作的数量超过一百个,我想到使用 Perl 来自动化该过程。

但是当我运行脚本时,我陷入了 vi 中,无法使其自行退出。这需要手动干预并且无法实现我的脚本的目的。我需要有关如何处理这种情况的帮助,因为这将帮助我节省时间和精力。

代码如下:

print "Enter job name - \n";
$job_rc = <>;
print "Job entered by you is $job_rc \n";
my @job_name = ("job1", "job2", "job3", "job4");
my $total_job = @job_name;
print "Total job present = $total_job + 1 \n";
for ($i = 0; $i < $total_job; $i++) {
    print "Curent job name: $job_name[$i] \n";
    system "cr_job $job_name[$i] $job_rc";
    sleep(10);
}

I have to run few jobs. After running each job, it runs vi on the contents. After writing and quitting (usually I do :wq!) those data get updated in the database. As the number of these kind of jobs is more than a hundred, I thought of automating the process using Perl.

But when I ran the script, I got stuck in vi, unable to make it exit on its own. This requires manual intervention and fails the purpose of my script. I need help on how to handle such situation as it will help me to save time and effort.

Code is as given below:

print "Enter job name - \n";
$job_rc = <>;
print "Job entered by you is $job_rc \n";
my @job_name = ("job1", "job2", "job3", "job4");
my $total_job = @job_name;
print "Total job present = $total_job + 1 \n";
for ($i = 0; $i < $total_job; $i++) {
    print "Curent job name: $job_name[$i] \n";
    system "cr_job $job_name[$i] $job_rc";
    sleep(10);
}

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

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

发布评论

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

评论(1

别理我 2025-01-14 09:48:55

我认为你从错误的角度处理这个问题。不要退出 vi,而是考虑不运行它。

我只能猜测为什么 vi 运行,它似乎与你的“工作”有关。可能的原因之一是他们运行默认的文本编辑器来获取一些用户输入(此类行为的众所周知的示例是当您调用 hg commit 时,svn commitcvs ci 等(在不提供消息的情况下,它们会自动运行文本编辑器来获取提交消息)。

如果是这种情况,请首先检查您的“工作”,因为他们可能有选项来禁用此提示。如果没有,他们可能会使用 $EDITOR 环境变量来决定运行哪个编辑器,将此变量设置为您准备的内容(例如,将默认消息写入作为参数给出的文件的脚本)可能做。

I think you approach the problem from the wrong side. Instead of exiting vi, think about not running it.

I can only guess why vi runs, it seems related to your “jobs”. One of the possible reasons is that they run a default text editor to grab some user input (well-known example of such behaviour is that when you call hg commit, svn commit, cvs ci, etc. without providing message, they automatically run a text editor to get the commit message).

If this is the case, first check your “jobs”, as they may have options to disable this very prompt. If not, they may be using the $EDITOR environment variable to decide which editor to run, setting this variable to something you prepare (for example, script which will write default message to file given as parameter) may do.

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