0

I am trying to call a batch file from Python 3.5:

The contents of the batch file are:

DataConverter.exe "\\BARYON-RL\MarketData\Raw\CFFEX\20161107" ".*.csv" "%MarketData%\CFFEX" "format_data_cffex_ctp.json" "HDF5"

The batch file runs fine when I run it manually so there is no problem there; however, when I run it in Python 3.5 using:

call('C:\\Users\\HP\\Dropbox\\TeamFolder\\Data\\Convert_Data_HDF5_SHFE_CTP.bat')

I get the error:

'DataConverter.exe' is not recognized as an internal or external command'

Why won't it work because I call if from Python?

meatspace
  • 769
  • 14
  • 24
Bazman
  • 1,832
  • 7
  • 38
  • 57
  • 2
    In the batch file, specify the full path to `DataConverter.exe`... How do you manually run the batch file? by double-clicking, or via command prompt? – aschipfl Nov 07 '16 at 21:26
  • 1
    That more insanity. Call the command straight from python. There is no need for a batch file and it very poor programming. –  Nov 07 '16 at 21:34
  • 2
    @aschipfl, it's probably the former, i.e. Explorer sets the working directory to the target file's directory when a file is run by double-clicking on it. In this case the batch file is naively assuming its directory is the working directory. It should use [`%~dp0`](http://stackoverflow.com/q/5034076/205580 "What does %~dp0 mean, and how does it work?"). Or just skip the batch file as suggested above. – Eryk Sun Nov 07 '16 at 22:04
  • 2
    Also, a post-Vista batch file is naive if it expects the working directory to be implicitly searched. The system may be configured securely by setting the environment variable [`NoDefaultCurrentDirectoryInExePath`](https://msdn.microsoft.com/en-us/library/ms684269), which affects cmd.exe and `CreateProcess` in general. – Eryk Sun Nov 07 '16 at 22:07

0 Answers0