Skip to content

Commit e2200ba

Browse files
authored
Introduce stdout and stderr parameter (#88)
1 parent f6d58fb commit e2200ba

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

src/main/python/RemoteSwingLibrary.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,6 @@ def __init__(self, port=0, debug=False, java9_or_newer='auto-detect'):
269269

270270
self._initiate(port, debug, java9_or_newer)
271271

272-
if os.path.exists(self._output("remote-stderr")):
273-
shutil.rmtree(self._output("remote-stderr"))
274-
if os.path.exists(self._output("remote-stdout")):
275-
shutil.rmtree(self._output("remote-stdout"))
276-
277272
def _initiate(self, port=0, debug=False, java9_or_newer='auto-detect'):
278273
if RemoteSwingLibrary.DEBUG is None:
279274
RemoteSwingLibrary.DEBUG = _tobool(debug)
@@ -395,7 +390,7 @@ def set_java_tool_options(self, close_security_dialogs=True, remote_port=0, dir_
395390
logger.debug("Set _JAVA_OPTIONS='%s'" % java_policy)
396391

397392
def start_application(self, alias, command, timeout=60, name_contains="", close_security_dialogs=False,
398-
remote_port=0, dir_path=None, custom=None):
393+
remote_port=0, dir_path=None, stdout=None, stderr=None, custom=None):
399394
"""Starts the process in the ``command`` parameter on the host operating system.
400395
The given ``alias`` is stored to identify the started application in RemoteSwingLibrary.
401396
@@ -412,27 +407,39 @@ def start_application(self, alias, command, timeout=60, name_contains="", close_
412407
``dir_path`` is the path where security dialogs screenshots are saved. It is working both with relative
413408
and absolute path. If ``dir_path`` is not specified the screenshots will not be taken.
414409
410+
``stdout`` is the path where to write stdout to.
411+
412+
``stderr`` is the path where to write stderr to.
413+
415414
``custom`` is a customizable field that can be set when starting the Java agent.
416415
"""
417416
close_security_dialogs = _tobool(close_security_dialogs)
418-
stdout = "remote-stdout" + "/" + "remote-stdout-" + re.sub('[:. ]', '-', str(datetime.datetime.now())) + '.txt'
419-
stderr = "remote-stderr" + "/" + "remote-stderr-" + re.sub('[:. ]', '-', str(datetime.datetime.now())) + '.txt'
420-
421-
stderr_dir = self._output("remote-stderr")
422-
stdout_dir = self._output("remote-stdout")
423-
424-
if not os.path.exists(stderr_dir):
425-
os.makedirs(stderr_dir)
417+
418+
now = datetime.datetime.now()
419+
current_date = now.strftime("%Y%m%d%H%M%S")
420+
421+
if stdout is None:
422+
stdout_file_name = current_date + ".remoteswinglibrary" + ".out"
423+
stdout = self._output(stdout_file_name)
424+
(stdout_dir, stdout_file_name) = os.path.split(stdout)
426425
if not os.path.exists(stdout_dir):
427426
os.makedirs(stdout_dir)
427+
428+
if stderr is None:
429+
stderr_file_name = current_date + ".remoteswinglibrary" + ".err"
430+
stderr = self._output(stderr_file_name)
431+
if stderr != "STDOUT":
432+
(stderr_dir, stderr_file_name) = os.path.split(stderr)
433+
if not os.path.exists(stderr_dir):
434+
os.makedirs(stderr_dir)
428435

429436
logger.info('<a href="%s">Link to stdout</a>' % stdout, html=True)
430437
logger.info('<a href="%s">Link to stderr</a>' % stderr, html=True)
431438
REMOTE_AGENTS_LIST.set_received_to_old()
432439
with self._agent_java_tool_options(close_security_dialogs, remote_port, dir_path, custom):
433440
self.PROCESS.start_process(command, alias=alias, shell=True,
434-
stdout=self._output(stdout),
435-
stderr=self._output(stderr))
441+
stdout=stdout,
442+
stderr=stderr)
436443
try:
437444
self._application_started(alias, timeout, name_contains, remote_port, accept_old=False)
438445
except TimeoutError:

0 commit comments

Comments
 (0)