9ls1
9ls1

Reputation: 145

"Press" enter "automatically" while the program is running

I'm calling an external program (fxTsUtf8.exe) from a bat-file or from a Python-file. I run through hundreds of sos-files. The exe-file may in some cases fail due to an error in the read sos-file. To continue the exe-file requires that the enter-key is pressed. How may I force "enter" to be input in such cases?

I'm running Windows 7 and Python 3.5. I have tried 2 approaches.

1) Only using a bat-file, tegnsett2utf8.bat, to call (have also tried start) C:\Fysak\fxTsUtf8.exe directly:

@echo off
REM For all subfolders 
for /D /r %%s in ("*") do (
  echo Subfolder %%~nxs
  REM For all sosifiles
  for %%f in (%%s\*.sos) do (
    echo File %%f
    call C:\Fysak\fxTsUtf8.exe %%f
  )
)

2) Calling a Python-file, 2utf8.py, from tegnsett2utf8.bat to run fxTsUtf8.exe:

@echo off
REM For all subfolders 
for /D /r %%s in ("*") do (
  echo Subfolder %%~nxs
  REM For all sosifiles
  for %%f in (%%s\*.sos) do (
    echo File %%f
    python 2utf8.py %%f
  )
)

where 2utf8.py looks like this

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys              # for å kunne lese variable
import subprocess       # for å starte et annet program

fn = sys.argv[1]

print('Python - filnavn er: '+fn)
print('----------------------------------------')
# Run fxTsUtf8 to convert to UTF-8 encoding
try:
    subprocess.call(['C:\\Fysak\\fxTsUtf8.exe', fn])
except RunTimeError:
    pass

Output on screen (in cmd-window) in both cases:

> C:\adhoc\SOSI_til_UTF8\Org\detalj\aas\aas21.sos Python - filnavn er:
> C:\adhoc\SOSI_til_UTF8\Org\detalj\aas\aas21.sos
> ----------------------------------------
> 
> fxTsUtf8 v. H1.1: Konverterer til UTF-8 tegnsett ...ORIGO-N├? mangler
> i filhodet. (Feil tegnsett?) Trykk [Enter] for Õ avbryte programmet:

But I couldn't figure out how to get the bat-file or the py-file to continue to the next sos-file without me hitting enter.

Upvotes: 1

Views: 1088

Answers (1)

rojo
rojo

Reputation: 24466

You could try

echo; | call C:\Fysak\fxTsUtf8.exe %%f

That should pipe a CRLF into the input buffer for call fxTsUtf8.exe.

Upvotes: 2

Related Questions