Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 直到一个永无止境的循环_Loops_Powershell - Fatal编程技术网

Loops 直到一个永无止境的循环

Loops 直到一个永无止境的循环,loops,powershell,Loops,Powershell,我已经写了一个Do..Until语句来检查文件是否存在。如果文件不在那里,它会等待几秒钟,然后再次检查 它应该在文件出现时结束。我已经通过在没有文件的情况下运行脚本进行了测试,然后在脚本运行时将其添加到文件夹中 它没有结束,而是继续无休止地循环。有人能看到我错过了什么吗 $path = test-path "C:\Temp\test.txt" do { if (!($path)) { Write-Host "Not here yet..." Sta

我已经写了一个
Do..Until
语句来检查文件是否存在。如果文件不在那里,它会等待几秒钟,然后再次检查

它应该在文件出现时结束。我已经通过在没有文件的情况下运行脚本进行了测试,然后在脚本运行时将其添加到文件夹中

它没有结束,而是继续无休止地循环。有人能看到我错过了什么吗

$path = test-path "C:\Temp\test.txt"
do {    
    if (!($path)) {
        Write-Host "Not here yet..."
        Start-Sleep -s 3
    }
} until($path)

Write-Host "Files here now"
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

测试路径
语句在行中计算

$path = Test-Path "C:\Temp\test.txt"
之后,变量
$path
包含计算的布尔结果。将实际支票放入您的条件中:

$path = "C:\Temp\test.txt"
do { 
    if (-not (Test-Path $path)) {
        Write-Host "Not here yet..."
        Start-Sleep -s 3
    }
} until (Test-Path $path)
function Test-File {
    Test-Path "C:\Temp\test.txt"
}

do { 
    if (-not (Test-File)) {
        Write-Host "Not here yet..."
        Start-Sleep -s 3
    }
} until (Test-File)
或者将其定义为在条件中调用的函数:

$path = "C:\Temp\test.txt"
do { 
    if (-not (Test-Path $path)) {
        Write-Host "Not here yet..."
        Start-Sleep -s 3
    }
} until (Test-Path $path)
function Test-File {
    Test-Path "C:\Temp\test.txt"
}

do { 
    if (-not (Test-File)) {
        Write-Host "Not here yet..."
        Start-Sleep -s 3
    }
} until (Test-File)

测试路径
语句在行中计算

$path = Test-Path "C:\Temp\test.txt"
之后,变量
$path
包含计算的布尔结果。将实际支票放入您的条件中:

$path = "C:\Temp\test.txt"
do { 
    if (-not (Test-Path $path)) {
        Write-Host "Not here yet..."
        Start-Sleep -s 3
    }
} until (Test-Path $path)
function Test-File {
    Test-Path "C:\Temp\test.txt"
}

do { 
    if (-not (Test-File)) {
        Write-Host "Not here yet..."
        Start-Sleep -s 3
    }
} until (Test-File)
或者将其定义为在条件中调用的函数:

$path = "C:\Temp\test.txt"
do { 
    if (-not (Test-Path $path)) {
        Write-Host "Not here yet..."
        Start-Sleep -s 3
    }
} until (Test-Path $path)
function Test-File {
    Test-Path "C:\Temp\test.txt"
}

do { 
    if (-not (Test-File)) {
        Write-Host "Not here yet..."
        Start-Sleep -s 3
    }
} until (Test-File)

测试路径
语句在行中计算

$path = Test-Path "C:\Temp\test.txt"
之后,变量
$path
包含计算的布尔结果。将实际支票放入您的条件中:

$path = "C:\Temp\test.txt"
do { 
    if (-not (Test-Path $path)) {
        Write-Host "Not here yet..."
        Start-Sleep -s 3
    }
} until (Test-Path $path)
function Test-File {
    Test-Path "C:\Temp\test.txt"
}

do { 
    if (-not (Test-File)) {
        Write-Host "Not here yet..."
        Start-Sleep -s 3
    }
} until (Test-File)
或者将其定义为在条件中调用的函数:

$path = "C:\Temp\test.txt"
do { 
    if (-not (Test-Path $path)) {
        Write-Host "Not here yet..."
        Start-Sleep -s 3
    }
} until (Test-Path $path)
function Test-File {
    Test-Path "C:\Temp\test.txt"
}

do { 
    if (-not (Test-File)) {
        Write-Host "Not here yet..."
        Start-Sleep -s 3
    }
} until (Test-File)

测试路径
语句在行中计算

$path = Test-Path "C:\Temp\test.txt"
之后,变量
$path
包含计算的布尔结果。将实际支票放入您的条件中:

$path = "C:\Temp\test.txt"
do { 
    if (-not (Test-Path $path)) {
        Write-Host "Not here yet..."
        Start-Sleep -s 3
    }
} until (Test-Path $path)
function Test-File {
    Test-Path "C:\Temp\test.txt"
}

do { 
    if (-not (Test-File)) {
        Write-Host "Not here yet..."
        Start-Sleep -s 3
    }
} until (Test-File)
或者将其定义为在条件中调用的函数:

$path = "C:\Temp\test.txt"
do { 
    if (-not (Test-Path $path)) {
        Write-Host "Not here yet..."
        Start-Sleep -s 3
    }
} until (Test-Path $path)
function Test-File {
    Test-Path "C:\Temp\test.txt"
}

do { 
    if (-not (Test-File)) {
        Write-Host "Not here yet..."
        Start-Sleep -s 3
    }
} until (Test-File)

好的,在发布这篇文章3分钟后(以及在沮丧之前一小时!)就想出来了

我需要把变量放在Do..Until语句中。像这样:

do{ 
    $path = test-path "C:\Temp\test.txt"
    if (!($path))   
        {Write-Host "Not here yet..."
        start-sleep -s 3}       
    }
until($path)
    Write-Host "Files here now"
    Write-Host "Press any key to continue ..."
    $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

好的,在发布这篇文章3分钟后(以及在沮丧之前一小时!)就想出来了

我需要把变量放在Do..Until语句中。像这样:

do{ 
    $path = test-path "C:\Temp\test.txt"
    if (!($path))   
        {Write-Host "Not here yet..."
        start-sleep -s 3}       
    }
until($path)
    Write-Host "Files here now"
    Write-Host "Press any key to continue ..."
    $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

好的,在发布这篇文章3分钟后(以及在沮丧之前一小时!)就想出来了

我需要把变量放在Do..Until语句中。像这样:

do{ 
    $path = test-path "C:\Temp\test.txt"
    if (!($path))   
        {Write-Host "Not here yet..."
        start-sleep -s 3}       
    }
until($path)
    Write-Host "Files here now"
    Write-Host "Press any key to continue ..."
    $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

好的,在发布这篇文章3分钟后(以及在沮丧之前一小时!)就想出来了

我需要把变量放在Do..Until语句中。像这样:

do{ 
    $path = test-path "C:\Temp\test.txt"
    if (!($path))   
        {Write-Host "Not here yet..."
        start-sleep -s 3}       
    }
until($path)
    Write-Host "Files here now"
    Write-Host "Press any key to continue ..."
    $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

你再也不查了。不知道那意味着什么对不起,但我明白了。Thanks@Chris您的变量
$path
不包含检查,但包含您在第一行执行的检查的结果。您再也不会检查了。不知道这意味着什么对不起,但我找到了答案。Thanks@Chris您的变量
$path
不包含检查,但包含您在第一行执行的检查的结果。您再也不会检查了。不知道这意味着什么对不起,但我找到了答案。Thanks@Chris您的变量
$path
不包含检查,但包含您在第一行执行的检查的结果。您再也不会检查了。不知道这意味着什么对不起,但我找到了答案。Thanks@Chris变量
$path
不包含检查,而是第一行中的检查结果。谢谢。但我几乎马上就明白了。当我发现之前的一个问题涉及到一个松散的卷曲括号(再见2个小时的“为什么?!”)时,我尝试了这个方法,但显然不起作用,所以我的大脑将它归档在“不要打扰”下。我无论如何都试过了,瞧!从技术上讲,你的答案是正确的,所以要这样做。再次感谢:)谢谢你。但我几乎马上就明白了。当我发现之前的一个问题涉及到一个松散的卷曲括号(再见2个小时的“为什么?!”)时,我尝试了这个方法,但显然不起作用,所以我的大脑将它归档在“不要打扰”下。我无论如何都试过了,瞧!从技术上讲,你的答案是正确的,所以要这样做。再次感谢:)谢谢你。但我几乎马上就明白了。当我发现之前的一个问题涉及到一个松散的卷曲括号(再见2个小时的“为什么?!”)时,我尝试了这个方法,但显然不起作用,所以我的大脑将它归档在“不要打扰”下。我无论如何都试过了,瞧!从技术上讲,你的答案是正确的,所以要这样做。再次感谢:)谢谢你。但我几乎马上就明白了。当我发现之前的一个问题涉及到一个松散的卷曲括号(再见2个小时的“为什么?!”)时,我尝试了这个方法,但显然不起作用,所以我的大脑将它归档在“不要打扰”下。我无论如何都试过了,瞧!从技术上讲,你的答案是正确的,所以要这样做。再次感谢:)