• <legend id='8ou3c'><style id='8ou3c'><dir id='8ou3c'><q id='8ou3c'></q></dir></style></legend>
  • <small id='8ou3c'></small><noframes id='8ou3c'>

      <i id='8ou3c'><tr id='8ou3c'><dt id='8ou3c'><q id='8ou3c'><span id='8ou3c'><b id='8ou3c'><form id='8ou3c'><ins id='8ou3c'></ins><ul id='8ou3c'></ul><sub id='8ou3c'></sub></form><legend id='8ou3c'></legend><bdo id='8ou3c'><pre id='8ou3c'><center id='8ou3c'></center></pre></bdo></b><th id='8ou3c'></th></span></q></dt></tr></i><div id='8ou3c'><tfoot id='8ou3c'></tfoot><dl id='8ou3c'><fieldset id='8ou3c'></fieldset></dl></div>
      <tfoot id='8ou3c'></tfoot>

        • <bdo id='8ou3c'></bdo><ul id='8ou3c'></ul>
      1. 通过 os.system 推送

        时间:2023-09-14

        • <legend id='3TzGy'><style id='3TzGy'><dir id='3TzGy'><q id='3TzGy'></q></dir></style></legend>

            <tfoot id='3TzGy'></tfoot>
                <bdo id='3TzGy'></bdo><ul id='3TzGy'></ul>

                <small id='3TzGy'></small><noframes id='3TzGy'>

                <i id='3TzGy'><tr id='3TzGy'><dt id='3TzGy'><q id='3TzGy'><span id='3TzGy'><b id='3TzGy'><form id='3TzGy'><ins id='3TzGy'></ins><ul id='3TzGy'></ul><sub id='3TzGy'></sub></form><legend id='3TzGy'></legend><bdo id='3TzGy'><pre id='3TzGy'><center id='3TzGy'></center></pre></bdo></b><th id='3TzGy'></th></span></q></dt></tr></i><div id='3TzGy'><tfoot id='3TzGy'></tfoot><dl id='3TzGy'><fieldset id='3TzGy'></fieldset></dl></div>
                    <tbody id='3TzGy'></tbody>
                • 本文介绍了通过 os.system 推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 crontab 为我的 minecraft 服务器运行维护脚本.大多数时候它工作正常,除非 crontab 尝试使用重启脚本.如果我手动运行重新启动脚本,则没有任何问题.因为我相信它与路径名有关,所以我试图确保它总是从 minecraft 目录执行任何 minecraft 命令.所以我将命令封装在 pushd/popd 中:

                  I'm using a crontab to run a maintenance script for my minecraft server. Most of the time it works fine, unless the crontab tries to use the restart script. If I run the restart script manually, there aren't any issues. Because I believe it's got to do with path names, I'm trying to make sure it's always doing any minecraft command FROM the minecraft directory. So I'm encasing the command in pushd/popd:

                  os.system("pushd /directory/path/here")
                  os.system("command to sent to minecraft")
                  os.system("popd")
                  

                  下面是一个交互式会话,将我的世界从等式中剔除.一个简单的ls"测试.如您所见,它根本没有从 pushd 目录运行 os.system 命令,而是从/etc/运行 python 来说明我的观点的目录.显然 pushd 不能通过 python 工作,所以我想知道我还能如何实现这一目标.谢谢!

                  Below is an interactive session taking minecraft out of the equation. A simple "ls" test. As you can see, it does not at all run the os.system command from the pushd directory, but instead from /etc/ which is the directory in which I was running python to illustrate my point.Clearly pushd isn't working via python, so I'm wondering how else I can achieve this. Thanks!

                  >>> def test():
                  ...     import os
                  ...     os.system("pushd /home/[path_goes_here]/minecraft")
                  ...     os.system("ls")
                  ...     os.system("popd")
                  ... 
                  >>> test()
                  ~/minecraft /etc
                  DIR_COLORS    cron.weekly  gcrypt         inputrc    localtime   mime.types         ntp       ppp         rc3.d       sasldb2         smrsh      vsftpd.ftpusers
                  DIR_COLORS.xterm  crontab      gpm-root.conf      iproute2   login.defs  mke2fs.conf            ntp.conf      printcap        rc4.d       screenrc        snmp       vsftpd.tpsave
                  X11       csh.cshrc    group          issue      logrotate.conf  modprobe.d         odbc.ini      profile         rc5.d       scsi_id.config  squirrelmail   vz
                  adjtime       csh.login    group-         issue.net  logrotate.d     motd               odbcinst.ini  profile.d       rc6.d       securetty       ssh        warnquota.conf
                  aliases       cyrus.conf   host.conf      java       lvm         mtab               openldap      protocols       redhat-release  security        stunnel        webalizer.conf
                  alsa          dbus-1       hosts          jvm        lynx-site.cfg   multipath.conf         opt       quotagrpadmins  resolv.conf     selinux         sudoers        wgetrc
                  alternatives      default      hosts.allow    jvm-commmon    lynx.cfg    my.cnf             pam.d         quotatab        rndc.key        sensors.conf    sysconfig      xinetd.conf
                  bashrc        depmod.d     hosts.deny     jwhois.conf    mail        named.caching-nameserver.conf  passwd        rc          rpc         services        sysctl.conf    xinetd.d
                  blkid         dev.d        httpd          krb5.conf  mail.rc     named.conf         passwd-       rc.d        rpm         sestatus.conf   termcap        yum
                  cron.d        environment  imapd.conf     ld.so.cache    mailcap     named.rfc1912.zones        pear.conf     rc.local        rsyslog.conf    setuptool.d     udev       yum.conf
                  cron.daily    exports      imapd.conf.tpsave  ld.so.conf     mailman     netplug            php.d         rc.sysinit      rwtab       shadow          updatedb.conf  yum.repos.d
                  cron.deny     filesystems  init.d         ld.so.conf.d   makedev.d   netplug.d          php.ini       rc0.d       rwtab.d         shadow-         vimrc
                  cron.hourly   fonts        initlog.conf   libaudit.conf  man.config  nscd.conf          pki       rc1.d       samba       shells          virc
                  cron.monthly      fstab        inittab        libuser.conf   maven       nsswitch.conf          postfix       rc2.d       sasl2       skel        vsftpd
                  sh: line 0: popd: directory stack empty
                  

                  ===(CentOS 服务器与 python 2.4)

                  === (CentOS server with python 2.4)

                  推荐答案

                  每个 shell 命令都在单独的进程中运行.它生成一个 shell,执行 pushd 命令,然后 shell 退出.

                  Each shell command runs in a separate process. It spawns a shell, executes the pushd command, and then the shell exits.

                  只需在同一个 shell 脚本中编写命令:

                  Just write the commands in the same shell script:

                  os.system("cd /directory/path/here; run the commands")
                  

                  更好的(也许)方法是使用 subprocess 模块:

                  A nicer (perhaps) way is with the subprocess module:

                  from subprocess import Popen
                  Popen("run the commands", shell=True, cwd="/directory/path/here")
                  

                  这篇关于通过 os.system 推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:应用程序找不到安装为 rpm 的 python 库 下一篇:“无法将'int'对象隐式转换为str"错误

                  相关文章

                  最新文章

                    <i id='MjLH8'><tr id='MjLH8'><dt id='MjLH8'><q id='MjLH8'><span id='MjLH8'><b id='MjLH8'><form id='MjLH8'><ins id='MjLH8'></ins><ul id='MjLH8'></ul><sub id='MjLH8'></sub></form><legend id='MjLH8'></legend><bdo id='MjLH8'><pre id='MjLH8'><center id='MjLH8'></center></pre></bdo></b><th id='MjLH8'></th></span></q></dt></tr></i><div id='MjLH8'><tfoot id='MjLH8'></tfoot><dl id='MjLH8'><fieldset id='MjLH8'></fieldset></dl></div>
                    • <bdo id='MjLH8'></bdo><ul id='MjLH8'></ul>

                  1. <small id='MjLH8'></small><noframes id='MjLH8'>

                      <tfoot id='MjLH8'></tfoot>

                    1. <legend id='MjLH8'><style id='MjLH8'><dir id='MjLH8'><q id='MjLH8'></q></dir></style></legend>