Skip to content

Commit 6a41483

Browse files
germa89pyansys-ci-botCopilotpre-commit-ci[bot]
authored
feat: add optional mapdl_output parameter to redirect MAPDL console output (#4388)
* feat: add optional mapdl_output parameter to redirect MAPDL console output * chore: adding changelog file 4388.added.md [dependabot-skip] * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * ci: auto fixes from pre-commit.com hooks. for more information, see https://pre-commit.ci --------- Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 66687ee commit 6a41483

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

doc/changelog.d/4388.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add optional mapdl_output parameter to redirect MAPDL console output

src/ansys/mapdl/core/launcher.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ def generate_mapdl_launch_command(
440440
ram: Optional[int] = None,
441441
port: int = MAPDL_DEFAULT_PORT,
442442
additional_switches: str = "",
443+
mapdl_output: Optional[str] = None,
443444
) -> list[str]:
444445
"""Generate the command line to start MAPDL in gRPC mode.
445446
@@ -474,6 +475,9 @@ def generate_mapdl_launch_command(
474475
these are already included to start up the MAPDL server. See
475476
the notes section for additional details.
476477
478+
mapdl_output : str, optional
479+
File path to redirect MAPDL console output (stdout). If not specified,
480+
a default temporary output file is used on Windows.
477481
478482
Returns
479483
-------
@@ -494,7 +498,9 @@ def generate_mapdl_launch_command(
494498

495499
# Windows will spawn a new window, special treatment
496500
if os.name == "nt":
497-
exec_file = f"{exec_file}"
501+
502+
tmp_out = mapdl_output if mapdl_output else ".__tmp__.out"
503+
498504
# must start in batch mode on windows to hide APDL window
499505
tmp_inp = ".__tmp__.inp"
500506
command_parm = [
@@ -505,7 +511,7 @@ def generate_mapdl_launch_command(
505511
"-i",
506512
tmp_inp,
507513
"-o",
508-
".__tmp__.out",
514+
tmp_out,
509515
additional_switches,
510516
port_sw,
511517
grpc_sw,
@@ -591,7 +597,7 @@ def launch_grpc(
591597
)
592598

593599
if mapdl_output:
594-
stdout = open(str(mapdl_output), "wb", 0)
600+
stdout = open(str(mapdl_output), "ab", 0)
595601
stderr = subprocess.STDOUT
596602
else:
597603
stdout = subprocess.PIPE # type: ignore
@@ -1798,6 +1804,7 @@ def launch_mapdl(
17981804
ram=args["ram"],
17991805
port=args["port"],
18001806
additional_switches=args["additional_switches"],
1807+
mapdl_output=args["mapdl_output"],
18011808
)
18021809

18031810
if args["launch_on_hpc"]:

0 commit comments

Comments
 (0)