How do I write a script that opens an iTerm2 window and runs a command? What I'm doing

I'm using iTerm2 Build 3.0.15 and writing a script that opens a new window and prints "hello world" to the screen. Really, I'm interested in being to run any command but using echo "hello world" as a starting point.

What I've tried

I read up on the iTerm2 documentation for scripting. I wanted to learn more so I dragged the iTerm2 icon on the Script Editor icon to view the dictionary available to me and found the following command:



From reading the dictionary and documentation I wrote the following script:

tell application "iTerm"
  create window with default profile command "echo hello world"
end tell


When I run my script from the terminal a new window opened and "hello world" was on the screen; however, I got the following broken pipe error:


When I select Ok the window closed and I'm left with the following message:

$ osascript iterm.applescript
window id 6415


The Questions


What do these broken pipe and window id 6415 errors mean?
How do I write a script that opens an iTerm2 window and runs a command?
Try this:

tell application "iTerm2"
    set newWindow to (create window with default profile)
    tell current session of newWindow
        write text "echo it works!"
    end tell
end tell


The write command, when not using without newline, executes the write text command because of the default added newline after the "text to send". Thus the window stays open after the command completes, ready for additional use.



From the iTerm AppleScript Dictionary:


  write v : Send text as though it was typed.
  
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;write specifier : The session to send to
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[contents of file file] : Filename to send the contents of
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[text text] : Text to send
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[newline boolean] : If newline should be added to end of text (default: yes)