diff --git a/src/Microsoft.PowerShell.Linux.Host/main.cs b/src/Microsoft.PowerShell.Linux.Host/main.cs
index e8605c79f5..d0f8e0f751 100644
--- a/src/Microsoft.PowerShell.Linux.Host/main.cs
+++ b/src/Microsoft.PowerShell.Linux.Host/main.cs
@@ -167,6 +167,16 @@ OPTIONS
///
private bool _showHelpMessage;
+ ///
+ /// To keep track whether last entered command was complete
+ ///
+ private bool incompleteLine = false;
+
+ ///
+ /// To store incomplete lines
+ ///
+ private string partialLine = string.Empty;
+
///
/// Gets or sets a value indicating whether the host application
/// should exit.
@@ -270,7 +280,11 @@ OPTIONS
return returnVal;
}
- // TODO: if we are in block mode, sep the prompt to ">> "
+ if (incompleteLine)
+ {
+ return ">> ";
+ }
+
Pipeline pipeline = rs.CreatePipeline();
Command promptCommand = new Command("prompt");
@@ -343,7 +357,15 @@ OPTIONS
{
this.currentPowerShell.Runspace = this.myRunSpace;
- this.currentPowerShell.AddScript(cmd);
+ if (incompleteLine)
+ {
+ this.currentPowerShell.AddScript(partialLine + cmd);
+ }
+ else
+ {
+ this.currentPowerShell.AddScript(cmd);
+ }
+ incompleteLine = false;
// Add the default outputter to the end of the pipe and then call the
// MergeMyResults method to merge the output and error streams from the
@@ -366,6 +388,16 @@ OPTIONS
this.currentPowerShell.Invoke(null, settings);
}
}
+ catch (IncompleteParseException e)
+ {
+ incompleteLine = true;
+ cmd = cmd.Trim();
+ partialLine += cmd;
+
+ partialLine += System.Environment.NewLine;
+
+ }
+
finally
{
// Dispose the PowerShell object and set currentPowerShell to null.
@@ -376,6 +408,11 @@ OPTIONS
this.currentPowerShell.Dispose();
this.currentPowerShell = null;
}
+
+ if (!incompleteLine)
+ {
+ partialLine = string.Empty;
+ }
}
}