Tried to open notepad.exe instead of Ember and same result... Process gets started and no notepad...
autoProcessMovie.py waits for notepad to close (returncode) so that it finishes its job.
I went to see how SABnzbd builds script command/arguments:
1st thing inside
https://github.com/sabnzbd/sabnzbd/blob/...sunpack.py
Code:
if sabnzbd.WIN32:
try:
import win32api
from win32con import SW_HIDE
from win32process import STARTF_USESHOWWINDOW, IDLE_PRIORITY_CLASS
except ImportError:
pass
else:
# Define dummy WindowsError for non-Windows
class WindowsError(Exception):
def __init__(self, value):
self.parameter = value
def __str__(self):
return repr(self.parameter)
As stated, external scripts get called from:
Code:
def external_processing(extern_proc, complete_dir, filename, msgid, nicename, cat, group, status):
""" Run a user postproc script, return console output and exit value
"""
command = [str(extern_proc), str(complete_dir), str(filename),
str(nicename), str(msgid), str(cat), str(group), str(status)]
if extern_proc.endswith('.py') and (sabnzbd.WIN32 or not os.access(extern_proc, os.X_OK)):
command.insert(0, 'python')
stup, need_shell, command, creationflags = [b][u]build_command(command)[/u][/b]
env = fix_env()
logging.info('Running external script %s(%s, %s, %s, %s, %s, %s, %s)',
extern_proc, complete_dir, filename, nicename, msgid, cat, group, status)
try:
p = subprocess.Popen(command, shell=need_shell, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
startupinfo=stup, env=env, creationflags=creationflags)
except:
logging.debug("Failed script %s, Traceback: ", extern_proc, exc_info = True)
return "Cannot run script %s\r\n" % extern_proc, -1
output = p.stdout.read()
ret = p.wait()
return output, ret
#------------------------------------------------------------------------------
And these parameters get populated inside "
build_command" function:
Code:
def build_command(command):
""" Prepare list from running an external program
"""
if not sabnzbd.WIN32:
if IONICE_COMMAND and cfg.ionice().strip():
lst = cfg.ionice().split()
lst.reverse()
for arg in lst:
command.insert(0, arg)
command.insert(0, IONICE_COMMAND)
if NICE_COMMAND and cfg.nice().strip():
lst = cfg.nice().split()
lst.reverse()
for arg in lst:
command.insert(0, arg)
command.insert(0, NICE_COMMAND)
need_shell = False
stup = None
creationflags = 0
else:
[b]need_shell = os.path.splitext(command[0])[1].lower() not in ('.exe', '.com')
stup = subprocess.STARTUPINFO()
stup.dwFlags = STARTF_USESHOWWINDOW
stup.wShowWindow = SW_HIDE
creationflags = IDLE_PRIORITY_CLASS[/b]
# Work-around for bug in Python's Popen function,
# scripts with spaces in the path don't work.
if need_shell and ' ' in command[0]:
command[0] = win32api.GetShortPathName(command[0])
if need_shell:
command = list2cmdline(command)
return stup, need_shell, command, creationflags
If I understand correctly, in my case I get:
stup = subprocess.STARTUPINFO() - Populate handle with default structure parameters.
Info for
STARTUPINFO structure
Code:
Specifies the window station, desktop, standard handles, and appearance of the main window for a process at creation time.
stup.dwFlags = STARTF_USESHOWWINDOW
Code:
STARTF_USESHOWWINDOW
0x00000001
The wShowWindow member contains additional information.
stup.wShowWindow = SW_HIDE
Code:
wShowWindow
If dwFlags specifies STARTF_USESHOWWINDOW, this member can be any of the values that can be specified in the nCmdShow parameter for the ShowWindow function, except for SW_SHOWDEFAULT. Otherwise, this member is ignored.
For GUI processes, the first time ShowWindow is called, its nCmdShow parameter is ignored wShowWindow specifies the default value. In subsequent calls to ShowWindow, the wShowWindow member is used if the nCmdShow parameter of ShowWindow is set to SW_SHOWDEFAULT.
So I suppose this parameter prevents cmd window opening after running command?!
need_shell = True ('cause my script doesn't end in '.exe' or '.com'.) - default shell 'cmd' i suppose
creationflags = IDLE_PRIORITY_CLASS
Code:
Processes that monitor the system, such as screen savers or applications that periodically update a display, should use IDLE_PRIORITY_CLASS. This prevents the threads of this process, which do not have high priority, from interfering with higher priority threads.
command = 'python nzbToCouchPotato.py [complete_dir] [filename] [nicename] [msgid] 'movies' [group] [status]'
Code:
command = [str(extern_proc), str(complete_dir), str(filename),
str(nicename), str(msgid), str(cat), str(group), str(status)]
Is the problem related to
stup.wShowWindow = SW_HIDE ? I suppose the shell window influences how windows apps get opened?
Get crazy with this. Might have to change to NZBGet
Thanks for your help!