我不熟悉python和powershell。为了尽可能地自动化我的测试,我尝试在对特定的.py文件进行更改时触发nosetests可执行文件在控制台上运行。在
到目前为止,我有下面的代码在文件中文件监视器.ps1. 当我在控制台上运行这个并对文件进行更改时词典.py控制台中会回响“Yippee”。好的开始。但是,我尝试了各种命令来调用操作块中的nosetests脚本。我的研究表明,类似这样的方法应该有效->;Invoke Command-ScriptBlock{&;$program}
但是,控制台上什么也没有发生。我认为这可能是因为nosetests需要从这个例子中的项目文件夹ieex48运行。但我不确定。在
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "C:\envs\projects\ex48\ex48"
$watcher.Filter = "lexicon.py"
$watcher.IncludeSubdirectories = $false
$watcher.EnableRaisingEvents = $true
$program = "C:\envs\acme\Scripts\nosetests.exe"
$changed = Register-ObjectEvent $watcher "Changed" -Action {
Write-Host "Yippee"
}
首先,为了安全起见,在powershell中不运行脚本
第二个 对于运行程序,您可以使用
^{pr2}$或者类似的
第三 如果要在
run.exe
或batch file
中运行powershell脚本 您可以使用此语法好的,你的剧本呢 System.IO.FileSystemWatcher只要看到你的路径,如果你创建了更改或删除通知你看到
如果您使用
add-content
生成txt文件,或者使用mkdir
生成目录,那么使用另一个powershell可以吗 创建: 或者在脚本中,您可以结束脚本调用$changed
相关问题 更多 >
编程相关推荐