Python API: Session Fails Immediately When Sending Command Through `Window.async_create()`
Note: I am 90% certain that what I am experiencing is my own fault with not understanding what the command
parameter is doing in the method call. Given that I am pretty certain this is me not understanding what is going on with this method, I held off on providing all the log information.
Thanks for filing an issue! Please answer the questions below so I can help you.
- iTerm2 version: 3.4.19
- OS version: Ventura 13.1
-
-
Attach ~/Library/Preferences/com.googlecode.iterm2.plist here (drag-drop from finder into this window)
-
- Attach a debug log, if possible. Instructions com.googlecode.iterm2.plistat https://iterm2.com/debuglog
-
-
Attach a screen capture video if it would make the reproduction steps clearer.
-
- Are you reporting a performance issue, excessive CPU usage, or a hang? Please attach a sample. Instructions at https://gitlab.com/gnachman/iterm2/wikis/HowToSampleScreen_Recording_2023-01-26_at_5.26.22_PM
- Are you reporting a crash? Please attach the crash log. Instructions at https://gitlab.com/gnachman/iterm2/wikis/crash-logs
- Are you reporting excessive memory usage? Please attach a heap analysis: https://gitlab.com/gnachman/iterm2/wikis/heapshot
PLEASE ATTACH YOUR PLIST FILE FOR BUG REPORTS! Seriously! I'll probably ask you for it if you don’t.
Script:
#!/usr/bin/env python3
import iterm2
# To install, update, or remove packages from PyPI, use Scripts > Manage > Manage Dependencies...
if __name__ == "__main__":
async def main(connection):
# Your code goes here. Here's a bit of example code that adds a tab to the current window:
app = await iterm2.async_get_app(connection)
initial_window = app.current_terminal_window
print(initial_window.window_id)
if initial_window is not None:
await iterm2.Window.async_create(connection, command="/bin/bash -l -c vi")
await initial_window.async_create(connection, profile="Default", command="ls -la")
else:
# You can view this message in the script console.
print("No current window")
iterm2.run_until_complete(main, True)
What happened: When I launch this script two windows get created. In the first window I run a command from the launch and run example; the second window launches my command, ls -la
. The command running with ls -la
seems to execute in the new window, but immediately after the session ends with a warning A session ended very soon after starting. Check that the command in profile "Default" is correct.
Note that under Profiles > Command
I have it selected as Login Shell
, and I have tried with Command
as well but the same behaviour results.
What should have happened: I should be able to send my ls -la
command to the window created by initial_window.async_create()
and have it execute in the new terminal instance.