Created
September 23, 2022 10:10
-
-
Save urasandesu/f8fa64f6770a6ac2744f25ec535bd63c to your computer and use it in GitHub Desktop.
PowerShell script to start JupyterLab with workspace URL directly. Now, the using browser is fixed by Chrome, so rewrite line 24 if you want to change to another one.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory = $True)] | |
[string] | |
$Workspace | |
) | |
Write-Verbose ('Workspace : {0}' -f $Workspace) | |
$psi = New-Object System.Diagnostics.ProcessStartInfo | |
$psi.FileName = 'jupyter-lab' | |
$psi.Arguments = '--no-browser' | |
$psi.UseShellExecute = $false | |
$psi.RedirectStandardError = $true | |
$p = [System.Diagnostics.Process]::Start($psi) | |
$task = $p.StandardError.ReadLineAsync() | |
while (!$p.WaitForExit(1)) { | |
if ($task.IsCompleted) { | |
$line = $task.Result | |
$uri = $null | |
if ([uri]::TryCreate($line, [System.UriKind]::Absolute, [ref]$uri) -and ![string]::IsNullOrEmpty($uri.Host)) { | |
$wsUri = New-Object uri $uri, $Workspace | |
start chrome $wsUri.AbsoluteUri | |
} | |
$line | |
$task.Dispose() | |
$task = $p.StandardError.ReadLineAsync() | |
} | |
else { | |
Start-Sleep 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment