문제

서버에서 새 버전을 감지 할 때 "자체 업데이트"하는 스크립트를 만들려고합니다.처음에는 내가 가진 아이디어가 새 버전이 감지되면 파일을 다운로드 한 다음 DOS 배치 파일을 시작하여 원본 EXE를 새 것으로 덮어 씁니다.나는 sytem을 사용할 수 있다고 생각했다 (update.bat 시작) 즉시 0을 종료하십시오..BAT 파일은 몇 초 동안 기다린 다음 Old Exe를 삭제하려고 시도합니다.이것은 실패합니다. 시스템 (시작 ...)을 사용하는 경우에도 새로운 "프로세스"가 실제로 동일한 프로세스 인 것입니다.Windows에서 Perl에서 완전히 새로운 프로세스를 시작할 수있는 방법이 있으므로 .EXE를 삭제할 수있게 해줍니다.아니면 더 좋을 다른 접근 방식이 있습니까?

고마워, 에릭 세이퍼

도움이 되었습니까?

해결책

See the documentation on the Windows Restart Manager, an API introduced with Windows Vista that manages restarting applications, for updates, for you.

다른 팁

Ever heard of java WebStart? There is a PAR equivalent, PAR::WebStart Basically, you configure it, then download code live from a trusted website

so your .exe would just be a frontend to PAR::WebStart, with the real program downloaded off your website

I know this is an old question, but I thought I'd put my solution here since I'm working on the same sort of thing. Your batch idea is the way I went, but the small change I made was to use exec() instead of system() since the former (according to this) "...executes a system command and never returns", which seems to release the running process. This appears to work both when running interpreted Perl files with Strawberry Perl, and when running compiled programs with PAR::Packer.

I've created test.pl, which was ultimately compiled to test.exe, as follows:

#!/usr/bin/perl

use 5.10.0;
use strict;
use warnings;

    my $batch_file = <<"BATCH";
rem ### IT IS SAFE TO DELETE THIS FILE ###

\@echo off
ping 127.0.0.1 -n 2 -w 1000 > nul
echo Copying over update file...
copy testfile.exe test.exe

BATCH

    open my $fh, '>', 'update.bat';
    print $fh $batch_file;
    close $fh;

    exec( 'update.bat' );

testfile.exe is a standby "upgraded" version of test.exe, just to make sure that I can overwrite test.exe while it's running, and I can. The ping is a way to pause for 2 seconds to make sure the process has had a chance to exit before trying to overwrite the file.

Oddly enough, the created batch file update.bat can't delete itself, even though batch files can normally delete themselves. If I create a batch file with this:

start /b "" cmd /c del %0

It will delete itself without any errors. But if I include that snippet in update.bat, it complains that The process cannot access the file because it is being used by another process. I'm not sure why. Since this isn't particularly important in my application, I haven't pursued this. I just leave update.bat behind and let it be overwritten next time an update occurs. But I do notate in the file that it's safe to delete in case anyone looks at it later.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top