Quantcast
Viewing all articles
Browse latest Browse all 11602

[Ruby] Comprobar si un archivo está siendo usado por algún proceso???

Llevo mucho tiempo trás esto...

El método de "comprobar el exitstatus" no me sirve para nada, engaña mucho, Por ejemplo he echo comprobaciones y el Winamp tarda 10 segundos en actualizarse en el "tasklist" (o al revés, el tasklist será el q tarda 10 segundos, no se)...

Resumiendo, Necesito una forma más nátiva y eficaz en Ruby para comprobar si un archivo está siendo usado por algún proceso (cualquier proceso):





porfavor, una ayuda, uds saben como hacerlo...








Código:

def Access(source_file, dest_file)
 begin
  ENV['tmp'] = $archivo.split('\\').last.split('.').first
  'cheat environment_variables --add'

  # CÓDIGO ORIGINAL:
  # system('start /b /MIN cmd /C Tasklist /v | Find "%tmp:~10%" >NUL')
  # ESTA PARTE HAY QUE MEJORARLA PARA QUE NO SE VEA LA CONSOLA

  system('Title MOVEMEBYELEKTRO & NirCMD win hide ititle "MOVEMEBYELEKTRO" & Tasklist /v | Find "%tmp:~10%" >NUL')

until $?.exitstatus.eql? 1 or $?.exitstatus.eql? 0
    sleep 0.1
end

  if $?.exitstatus.eql? 0
      reintentar($archivo.encode('utf-8').gsub("\û", "-"), ARGV[0])
  end

  if $?.exitstatus.eql? 1
      FileUtils.mv $archivo.encode('utf-8').gsub("\û", "-"), ARGV[0]
  end
 
 rescue
  reintentar($archivo.encode('utf-8').gsub("\û", "-"), ARGV[0])
 end
end

PD: Repito, el code no me sirve xD, necesito otra forma para comprobarlo

Viewing all articles
Browse latest Browse all 11602

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>