免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2726 | 回复: 8
打印 上一主题 下一主题

这么个小问题我都没搞定,在线等 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-01-11 10:59 |只看该作者 |倒序浏览
很简单的啦,就是  
cd   /usr/local/batch/office/bin  
nohup ./startserver.sh &

这样子2步用perl的system写,可我都写得不对
#!/usr/bin/perl
system(cd   /usr/local/batch/office/bin);
system(nohup ./startserver.sh &);

  ---这样执行不了的吧?我改成:

#!/usr/bin/perl
system "cd","/usr/local/batch/office/bin";
system "nohup","./startserver.sh","&";

  ---这样好像也不行,我对这个调用的内部实现还不清楚,所以不知道怎么写,在线等,谢谢。
---顺便说下,我有3个要执行,所以写批处理文件,因为刚学perl要利用起来。

论坛徽章:
0
2 [报告]
发表于 2011-01-11 11:14 |只看该作者
回复 1# 穆赫兰道


直接执行/usr/local/batch/office/bin/startserver.sh,
你system里面cd是cd不到那里去的

论坛徽章:
0
3 [报告]
发表于 2011-01-11 11:18 |只看该作者
回复 1# 穆赫兰道
切换工作目录,用chdir

论坛徽章:
0
4 [报告]
发表于 2011-01-11 11:31 |只看该作者
上面的方法都不错的
另外,多个命令可以合在一个语句里:
cd  /usr/local/batch/office/bin && nohup ./startserver.sh &

论坛徽章:
0
5 [报告]
发表于 2011-01-11 12:50 |只看该作者
谢谢各位
我的执行命令必须是:
nohup ./startServer.sh &
或者 nohup /usr/local/batch/base/startServer.sh &

必须用nohup 命令,必须加& 号。我用chdir,修改了下:
#!/usr/bin/perl
chdir "/usr/local/batch/office/bin";
system "nohup","./startServer.sh","&";
        -----服务是能启动了,但是好像不是以 nohup方式来启的,退出终端 服务就挂了,
    还需要怎么改?

论坛徽章:
0
6 [报告]
发表于 2011-01-11 12:56 |只看该作者
不行就算了,用其他吧
#!/bin/bash
nohup  /usr/local/batch/office/bin/startserver.sh &

这样是ok的,但是我就想用perl调用。

论坛徽章:
0
7 [报告]
发表于 2011-01-11 16:47 |只看该作者
system(cd   /usr/local/batch/office/bin; nohup ./startserver.sh & );

论坛徽章:
0
8 [报告]
发表于 2011-01-11 17:23 |只看该作者
system(cd   /usr/local/batch/office/bin; nohup ./startserver.sh & );
James_Guan 发表于 2011-01-11 16:47



   
If there is only one scalar argument, the argument is checked for shell metacharacters, and if there are any, the entire argument is passed to the system's command shell for parsing (this is /bin/sh -c on Unix platforms, but varies on other platforms). If there are no shell metacharacters in the argument, it is split into words and passed directly to execvp , which is more efficient.


樓上有點小失誤:
  1. system('cd /usr/local/batch/office/bin; nohup ./startserver.sh &');
复制代码

论坛徽章:
0
9 [报告]
发表于 2011-05-19 09:36 |只看该作者
回复 5# 穆赫兰道


    多参数调用system的时候,可以避免调用shell,但同时也失去了shell的重定向,后台执行等特性,所以退出终端命令就结束了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP