Run wine commands from Python 3.6 on Mac OSX

I am trying to write a script in Python which opens wine and then sends code to the wine terminal to open a .exe program. The .exe program is also command driven.

I can open wine, but I can't get any further:

import shlex, subprocess line = "/usr/bin/open -n -a /Applications/Wine\ Stable.app" line2 = '''cd /Applications/application/ && wine application.exe /h1 /k0 Z:/Users/myname/Desktop/File.TXT''' line = shlex.split(line) p1 = subprocess.Popen(line) p1.stdin.write(line2.encode())

The above doesn't work, wine doesn't seem to receive line2, although

/usr/bin/open -n -a /Applications/Wine\ Stable.app

by itself is fine (it opens Wine but nothing else.)

I'm pretty confused about what the next step should be. I would like to avoid additional dependencies if possible, because it seems simple.


The following has worked for me in many cases (on Linux):

import subprocess command = 'echo "echo foo && echo bar" | wine cmd > std_out.txt 2> std_error.txt &' subprocess.Popen(command, shell = True)

(I believe wine is also available as a command on MacOS, just like that. Please correct me if I am wrong.)

The command fires up a Windows/DOS-like shell (wine cmd). You can actually type wine cmd into your Linux shell and hit enter - you'll find yourself in a DOS shell. The next step is to get commands into the DOS shell. I do this by piping them into it as a string. In my example, I run two commands: echo foo and echo bar. The initial echo writes the command string to stdout, the following | opens a pipe and forwards the string into the DOS shell.

Besides, once you send commands to the DOS shell, keep in mind that it expects Windows paths (when you change directories etc). I.e. you must translate your Unix paths into Windows paths before you send them into the DOS shell. You can automatically convert your path on a command line like this ...

winepath -w /home/ 2> /dev/null

... resulting in Z:\home\ (for example). Alternatively, the following Python snipped will do the same for you:

def convert_unix_path_to_windows_path(in_path): cmd = ['winepath', '-w', in_path] proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (out, err) = proc.communicate() return out.decode('utf-8').strip()


  • OSError: [Errno 8] Exec format error with GeckoDriver and Selenium on MacOS
  • Could not load file or assembly in Visual Studio 2012, C#
  • How can I get the reply of SMS that sent to a mobile device?
  • How can I cast an expression from type interface, to an specific type
  • browserify 'Error: Cannot find module' in trying to fix 'Uncaught reference error: re
  • VSTS - App Center - Yaml - Endpoint could not be found
  • How to solve Access denied in gitlab?
  • How do I call templates with same names at different directories in Django?
  • Rails actionmailer open host email app
  • Set= log.txt in batch
  • LINQ - search between IList and list of strings
  • EGit and multiple “users” on same machine
  • Python subprocess communicate kills my process
  • Open Video file in VLC through Python
  • How to fork and exec a server and wait until it's ready?
  • os.system not working, but typing the same thing into the command prompt works
  • Programmatically check if PHP is installed using Python
  • Downloading files from Google Storage using Spark (Python) and Dataproc
  • Read stdin in chunks in Bash pipe
  • System call time out?
  • Retrieving a contacts notes
  • subprocess.Popen('start') fails
  • Special chars in Amazon S3 keys?
  • Encode Byte array to JPEG image in Objective-C
  • How can I count unique terms in a plaintext file case-insensitively?
  • Serve file to user over http via php
  • Interpreting STRACE output - pipes and forks
  • apply a javascript function to draggable copy
  • Consuming a WCF service in a Java Client using wsHttpBinding
  • Exception gevent.hub.LoopExit: LoopExit('This operation would block forever',)
  • MS Access - How to change the linked table path by amend the table
  • Python CGI os.system causing malformed header
  • Window Size for Mac application
  • WOWZA + RTMP + HTML5 Playback?
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Comma separated Values
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • coudnt use logback because of log4j
  • How to load view controller without button in storyboard?