Ich stelle vor, wie man eine Datei mit absolutem Pfad von der WSL-Linux-Bash-Befehlszeile an PowerShell übergibt und öffnet.
Anscheinend ist WSL-Bash nicht gut darin, Dateien mit absoluten Pfaden zu öffnen.
Mit cmd /c können Sie absolute Pfade verwenden, die mit C:/ beginnen, aber mit PowerShell, selbst wenn Sie powershell . C:/hoge/hoge.mp4 machen
Passiert dies.
$ psl . C:\_videos\agd\video_20180824_104256.mp4
. : The term 'C:_videosagdvideo_20180824_104256.mp4' is not recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:3
+ . C:_videosagdvideo_20180824_104256.mp4
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:_videosagdvideo_20180824_104256.mp4:String) [], CommandNotFoundExcept
ion
+ FullyQualifiedErrorId : CommandNotFoundException
Wie wäre es dann mit /mnt/-Pfaden?
$ psl . /mnt/c/_videos/agd/video_20180824_104256.mp4
. : The term '/mnt/c/_videos/agd/video_20180824_104256.mp4' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At line:1 char:3
+ . /mnt/c/_videos/agd/video_20180824_104256.mp4
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (/mnt/c/_videos/...0824_104256.mp4:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Also können absolute Pfade einfach nicht geöffnet werden. Nun, ich meine, sie können von der Eingabeaufforderung aus geöffnet werden… aber jedes Mal /mnt/ → C: zu konvertieren… und ich habe kürzlich vom wslpath-Befehl erfahren, aber ich kann ihn aus irgendeinem Grund nicht verwenden… Nun, es ist in Beta, also denke ich, es ist schneller, solche Fehler selbst zu überwinden, als auf Korrekturen zu warten.
Da also absolute Pfade unmöglich sind, lassen Sie uns in relative Pfade konvertieren und die Datei öffnen.
python -c "import os.path; print os.path.relpath('[absoluter Pfad der Zieldatei]', '[aktueller Pfad]')"
Es scheint, dass Sie den relativen Pfad mit einem Python-Einzeiler so berechnen können. Rubys expand_path(”,FILE) würde wahrscheinlich auch funktionieren.
Also mache ich das:
$ python -c "import os.path; print os.path.relpath('/mnt/c/_videos/agd/video_20180824_104256.mp4', '$(echo $PWD)')"
../_videos/agd/video_20180824_104256.mp4
Sieht gut aus.
psl . $(python -c "import os.path; print os.path.relpath('/mnt/c/_videos/agd/video_20180824_104256.mp4', '$(echo $PWD)')")
… Es hat sich geöffnet. (psl ist ein benutzerdefinierter Alias für powershell.exe.)