v79italya, пробуйте (на PowerShell):
Скрытый текст
Код:
$sArchiveFile = 'C:\Мои проекты\0272\project.iwprj2'
$sSourceFileName = 'project'
$sPath27Za = "$($env:ProgramFiles)\7-Zip\7za.exe"
if([System.IO.File]::Exists($sArchiveFile)) {
if([System.IO.File]::Exists($sPath27Za)) {
$oProcess = New-Object -TypeName 'System.Diagnostics.Process'
$oProcess.StartInfo.FileName = $sPath27Za
$oProcess.StartInfo.Arguments = "e -y -sccWIN -o""$($env:TEMP)"" ""$sArchiveFile"" ""$sSourceFileName"""
$oProcess.StartInfo.CreateNoWindow = $true
$oProcess.StartInfo.UseShellExecute = $false
$oProcess.StartInfo.RedirectStandardOutput = $true
if($oProcess.Start()) {
Write-Host "Trying extract source file [$sSourceFileName] from archive [$sArchiveFile] into temp folder [$($env:TEMP)]." -ForegroundColor Green
$oProcess.WaitForExit()
Write-Host $($oProcess.StandardOutput.ReadToEnd()) -ForegroundColor Cyan
if($oProcess.ExitCode -eq 0) {
$sTempFile = "$($env:TEMP)\$sSourceFileName"
Write-Host "Trying find and replace value in extracted file [$sTempFile]." -ForegroundColor Green
try {
$oXmlDocument = [System.Xml.XmlDocument](Get-Content -Path $sTempFile)
$oXmlDocument.StateOfInfoProject.CaptchaID = '27'
$oXmlDocument.Save($sTempFile)
} catch {
Write-Host "Can't find and replace value in extracted file [$sTempFile]." -ForegroundColor Red
}
$oProcess.StartInfo.Arguments = "u -y -sccWIN ""$sArchiveFile"" ""$sTempFile"""
if($oProcess.Start()) {
Write-Host "Trying update source file [$sSourceFileName] in archive [$sArchiveFile] from previously extracted file [$sTempFile]." -ForegroundColor Green
$oProcess.WaitForExit()
Write-Host $($oProcess.StandardOutput.ReadToEnd()) -ForegroundColor Cyan
if($oProcess.ExitCode -eq 0) {
Write-Host "Delete temporary file [$sTempFile]." -ForegroundColor Green
[System.IO.File]::Delete($sTempFile)
} else {
Write-Host "Can't update file [$sSourceFileName] in archive [$sArchiveFile] from file [$sTempFile] correctly. 7za.exe return non-zero exit code: $($oProcess.ExitCode)." -ForegroundColor Red
}
} else {
Write-Host "Can't execute [$($oProcess.StartInfo.FileName)] with arguments [$($oProcess.StartInfo.Arguments)] normally." -ForegroundColor Red
}
} else {
Write-Host "Can't extract source file [$sSourceFileName] from archive [$sArchiveFile] correctly. 7za.exe return non-zero exit code: $($oProcess.ExitCode)." -ForegroundColor Red
}
} else {
Write-Host "Can't execute [$($oProcess.StartInfo.FileName)] with arguments [$($oProcess.StartInfo.Arguments)] normally." -ForegroundColor Red
}
} else {
Write-Host "Can't find executable file [$sPath27Za]." -ForegroundColor Red
}
} else {
Write-Host "Can't find archive file [$sArchiveFile]." -ForegroundColor Red
}
Цитата Busla:
алгоритм разработан так что получает поток и отдаёт поток - последовательность данных в один проход
для них возможно выдавать в stdout
Цитата:
If the -so switch is used with the command that creates archive, it works only with some archive formats: xz, gzip, bzip2 and tar.
|
»
|
Busla, спасибо, ясно. Ну, в данном случае как раз таки gzip.
Цитата Busla:
"обработать ситуацию" - это если не нашёлся 7zip, поискать WinRar »
|
Не могу с Вами согласиться, коллега.
Цитата Busla:
а ваша обработка в стиле вместо ошибки (с ошибочным кодом возврата) написать красный текст с нормальным кодом завершения - это медвежья услуга »
|
Это правильно, но меня дико бесит отлаживать такие ситуации в ISE — понимаете, почему.
А писать красным текстом я перестану не раньше, чем этим перестанет заниматься Microsoft.
Цитата greg zakharov:
Нормально. А должно быть иначе? »
|
Раз у Вас нормально, значит, проблемы на моей стороне.
Цитата Sham:
С sed'ом работает и bom-метку сохраняет, но через временный файл только »
|
А у меня и напрямую
код коллеги
greg zakharov отработал. Про метку BOM — что б ему не сохранять? Вот с UTF-16LE/1200 с BOM — там интереснее должно получиться.
Я особо не ковырял.