Shell.ReadOutputText
--------------------

Reads output.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Shell](component_Shell.md) | [7.5](newinversion75.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ❌ No |

MBS( "Shell.ReadOutputText"; ShellRef { ; Encoding } ) 

**MBS**( **"Shell.ReadOutputText";** /\* Reads output. \*/  
**$ShellRef**; /\* The reference number from the shell.e.g. $shell \*/   
**$Encoding**) /\* Optional; The text encoding for result.e.g. UTF8 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| ShellRef | The reference number from the shell. | $shell |  |
| Encoding | The text encoding for result.   Possible encoding names: ANSI, ISO-8859-1, Latin1, Mac, Native, UTF-8, DOS, Hex, Base64 or Windows. More listed in the [FAQ](https://www.monkeybreadsoftware.com/filemaker/faq.shtml). | UTF8 | Optional |

### Result

Returns text or error.

### Description

Reads output.  
When child process writes something to output stream, you can read it here.  
See also [Shell.ReadErrorText](ShellReadErrorText.md) for reading error output.  
  
The plugin internally queries [Shell.AvailableBytesOutput](ShellAvailableBytesOutput.md) to see how much to read and return.  
  
Some processes send data in chunks, so you have to read one chunk before you get the next one. So you may do a loop with calling [Shell.Wait](ShellWait.md) with e.g. 0.1 seconds. Check with [Shell.IsRunning](ShellIsRunning.md) whether app is still running, so you can exit the loop if needed. And each time the loop runs, check if there is new output and read it.  
### Examples

Loop and collect messages:

 Set Variable \[ $error ; Value: "" \]   
Set Variable \[ $result ; Value: "" \]   
\# Loop while app runs and collect messages   
Loop  
 # Wait a second or till it quits  
 Set Variable \[ $s ; Value: MBS ( "[Shell.Wait](ShellWait.md)"; $shell ; 1) \]   
 # And read output  
 Set Variable \[ $error ; Value: $error &amp; MBS ( "[Shell.ReadErrorText](ShellReadErrorText.md)"; $shell ; "UTF-8") \]   
 Set Variable \[ $result ; Value: $result &amp; MBS ( "Shell.ReadOutputText"; $shell ; "UTF-8") \]   
 Set Field \[ Shell::Error ; MBS ( "[Text.ReplaceNewLine](TextReplaceNewLine.md)"; $error ; 1) \]   
 Set Field \[ Shell::Output ; MBS ( "[Text.ReplaceNewLine](TextReplaceNewLine.md)"; $result ; 1) \]   
 # exit when done  
 Exit Loop If \[ MBS ( "[Shell.IsRunning](ShellIsRunning.md)"; $shell ) ≠ 1 \]   
End Loop  
### See also

- [Shell.AvailableBytesOutput](ShellAvailableBytesOutput.md)
- [Shell.CloseInput](ShellCloseInput.md)
- [Shell.Execute](ShellExecute.md)
- [Shell.IsRunning](ShellIsRunning.md)
- [Shell.PeekOutputText](ShellPeekOutputText.md)
- [Shell.ReadErrorText](ShellReadErrorText.md)
- [Shell.SetDataAvailableScript](ShellSetDataAvailableScript.md)
- [Shell.Wait](ShellWait.md)
- [Shell.WriteInputText](ShellWriteInputText.md)
- [Text.ReplaceNewLine](TextReplaceNewLine.md)

### Release notes

- **Version 11.2**
    - Changed a couple of internal text functions to recognize that text with UTF-8 as a BOM for UTF-16 or UTF-32 and then reinterpret bytes to handle that. Useful for [Shell.ReadOutputText](https://www.mbsplugins.eu/ShellReadOutputText.shtml), when a command line tool outputs UTF-16 instead of expected UTF-8.

### Example Databases

- [Mac and iOS/PDFKit/PDFKit Print Documents](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Mac%20and%20iOS/PDFKit/PDFKit%20Print%20Documents.shtml#4ScriptAnchor_)
- [Shell/Shell Ping](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Shell/Shell%20Ping.shtml#1ScriptAnchor_)
- [Shell/Shell](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Shell/Shell.shtml#1ScriptAnchor_)
- [Shell/Terminal](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Shell/Terminal.shtml#3ScriptAnchor_)

### Blog Entries

- [Convert Office Files in FileMaker](https://www.mbsplugins.de/archive/2022-07-04/Convert_Office_Files_in_FileMa/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 11.2pr1](https://www.mbsplugins.de/archive/2021-04-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Tip of the day: Shell Execute as one Let statement](https://www.mbsplugins.de/archive/2019-11-07/Tip_of_the_day_Shell_Execute_a/monkeybreadsoftware_blog_filemaker)
- [Run fmsadmin from script](https://www.mbsplugins.de/archive/2019-05-28/Run_fmsadmin_from_script/monkeybreadsoftware_blog_filemaker)
- [Convert office documents to PDF with LibreOffice](https://www.mbsplugins.de/archive/2018-06-15/Convert_office_documents_to_PD/monkeybreadsoftware_blog_filemaker)
- [Tips for FileMaker Data Migration Tool](https://www.mbsplugins.de/archive/2018-06-09/Tips_for_FileMaker_Data_Migrat/monkeybreadsoftware_blog_filemaker)
- [Execute defaults command with Shell functions](https://www.mbsplugins.de/archive/2017-12-21/Execute_defaults_command_with_/monkeybreadsoftware_blog_filemaker)
- [Convert to MP3 with new Shell commands and ffmpeg](https://www.mbsplugins.de/archive/2017-11-16/Convert_to_MP3_with_new_Shell_/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 11st November 2017 , last changed 28th January 2022

  
[Shell.ReadErrorText](ShellReadErrorText.md) - [Shell.Release](ShellRelease.md)

[HTML Version](ShellReadOutputText.shtml)