将基于Unix的PHP脚本转换为Windows的批处理文件

问题描述:

我想将这个在Unix系统上运行良好的PHP脚本转换为Windows脚本。将基于Unix的PHP脚本转换为Windows的批处理文件

我不知道如何重写它。有人能帮我吗?

下面是脚本:

$cmd = 'nohup sudo -u '.$user.' bash -c "cd ' . 
escapeshellarg($path) . '; VVERBOSE=true QUEUE=' . 
escapeshellarg($queue) . ' APP_INCLUDE=' . 
escapeshellarg($bootstrap_path) . ' INTERVAL=' . 
escapeshellarg($interval) . ' CAKE=' . 
escapeshellarg(CAKE) . ' COUNT=' . $count . 
' php ./resque.php'; 
$cmd .= ' > '. escapeshellarg($log_path).' 2>&1" >/dev/null 2>&1 &'; 

passthru($cmd); 
+6

这不是一个bash脚本!它看起来更像perl或PHP。 –

+1

另外,一个更好的想法是描述你想做什么(以及你自己试图解决这个问题),而不是让我们尝试解码你的脚本 –

中继是在PHP的方法见http://php.net/manual/en/function.passthru.php

你知道剧本做什么?也许反向工程到windows批处理脚本?

  • 执行命令以其他用户身份
  • 改变当前目录
  • 设置环境变量
  • 调用:

    从外观上来看,该脚本从一个* nix的系统,它来了直接从PHP解释器获取PHP脚本并将日志转储到文件中,并将管道传递到/ dev/null

这个脚本是imo,不可能“隐藏”到Windows批处理脚本(因为Windows!= POSIX),所以你需要重写它。

+0

谢谢比尔,它正是我所知道的,这个PHP脚本在unix系统上使用,为什么它使用像sudo,bash等命令...我想重写它,但我真的不知道该怎么做,你能帮我或给我一种方法学习如何?谢谢 –

+0

对于初学者来说,唯一不能移植的命令是nohup(?)和windows中的sudo。其余的应该相对容易。 - cd(linux),cd(windows) - http://support.microsoft.com/kb/110930重定向stdout和err - set(windows)用于设置变量。 为什么你需要将它转换为Windows? – Bill

+0

因为我在当地的窗口工作。我只是试图得到它与cygwin的工作,我已经删除了“nohup sudo”,但它仍然是一个错误。这里是$ cmd的内容:bash -c“cd”D:\ WebServer \ www \ MyProject \ app \ Plugin \ Resque \ Vendor \ php-resque \“; VVERBOSE = true QUEUE =”default“APP_INCLUDE =”D: \ WebServer \ www \ MyProject \ lib \ Cake \“COUNT = 1 php ./resque.php”INTERVAL =“5”CAKE =“D:\ WebServer \ www \ MyProject \ app \ Plugin \ Resque \ Lib \ ResqueBootstrap.php >“D:\ WebServer \ www \ MyProject \ app \ tmp \ logs \ php-resque-worker.log”2>&1“>/dev/null 2>&1& –