You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
nu::shell::io_error when trying to run file on windows #13020
changed the title [-]`nu::shell::io_error` when trying to run powershell .ps1 script [windows][/-][+]`nu::shell::io_error` when trying to run file on windows[/+]on May 31, 2024
After further inspection this has nothing to do with powershell, I can replicate the bug by creating an empty test.txt file and running in nushell ./test.txt
I can't really figure out why this would have worked before. Maybe because I don't have this configured, but it seems like you also have to set PATHEXT and have the registry file association to open it?
But ultimately we're still passing the ps1 file to std::process::Command::new(), which is what was happening before too as far as I can tell. I don't think this was triggering the behaviour where it was getting passed to cmd.exe because that was special cased for .cmd and .bat files.
Executing nushell scripts should be fixed. Executing bat and cmd seems to work fine. Executing ps1 may not be something nushell needs to do without pwsh.exe. Executing text files is definitely not something nushell should do, that relies on windows and the file extension association system. That's what the start command is about.
Executing ps1 may not be something nushell needs to do without pwsh.exe. Executing text files is definitely not something nushell should do, that relies on windows and the file extension association system.
I think the problem here is the apparent lack of design. Thus all these maybes and shoulds. When design is unclear the observable behavior becomes the design. As such, I can only agree that this is a regression. The issue shouldn't be closed as if it was resolved. Either it should be reopened, or closed as "won't fix".
We welcome people to come in and design things. However, we can't design everything since we're staffed by a team of volunteers, there are a million little details, and the team mostly does what they're interested in, like any open-source project.
I can ask the core-team if they think ps1 files should be launch-able without specifying pwsh.exe and see what they think, so it's not only me making decisions. We also have weekly meetings that are open to the public that people can join and discuss items important to them.
Side note, if we wanted to execute ps1 files we'd also have to know if the user wants to run powershell.exe or pwsh.exe. I'm not sure how we'd tell that by doing just "./test.ps1".
If we do allow .ps1 to be easily executed, it opens up the possibility of consuming powershell output pretty easily. I mean the same thing could happen with powershell -Command 'Get-ChildItem | ConvertTo-Json' but it's a tad bit easier to have a script like below.
Activity
[-]`nu::shell::io_error` when trying to run powershell .ps1 script [windows][/-][+]`nu::shell::io_error` when trying to run file on windows[/+]Araxeus commentedon May 31, 2024
After further inspection this has nothing to do with powershell, I can replicate the bug by creating an empty
test.txtfile and running in nushell./test.txtfdncred commentedon May 31, 2024
Did those work before 0.94.0? Seems like ps1 files would need
pwsh file.ps1and.txtfiles are not executable.Araxeus commentedon May 31, 2024
@fdncred I confirmed it used to work on v0.93.0, and broke on v0.94.0
seems like #12921 broke it?
kubouch commentedon May 31, 2024
Duplicate of #13016.Araxeus commentedon May 31, 2024
doesn't look like it? neither description nor how to reproduce?
did u debug why this is happening and saw it is the same reason or what?
also it broke on v0.94.0 not v0.94.1?
kubouch commentedon May 31, 2024
Ah, oops, sorry, too many tabs open :-D.
devyn commentedon Jun 1, 2024
I can't really figure out why this would have worked before. Maybe because I don't have this configured, but it seems like you also have to set
PATHEXTand have the registry file association to open it?But ultimately we're still passing the ps1 file to
std::process::Command::new(), which is what was happening before too as far as I can tell. I don't think this was triggering the behaviour where it was getting passed tocmd.exebecause that was special cased for.cmdand.batfiles.Araxeus commentedon Jun 1, 2024
dont know much about nu architecture but after some debugging I figured out alot.
the current error in v0.94.0 is thrown here in
command.spawn():nushell/crates/nu-command/src/system/run_external.rs
Line 161 in f3cf693
nushell/crates/nu-system/src/foreground.rs
Lines 35 to 39 in f3cf693
but here is what was happening in previous versions (<v0.93.0):
input =
./typos.tomlthe code gets to here:
nushell/crates/nu-command/src/system/run_external.rs
Lines 174 to 177 in 3b220e0
and fails with
{ code: 193, kind: Uncategorized, message: "%1 is not a valid Win32 application." }then we get to:
nushell/crates/nu-command/src/system/run_external.rs
Lines 216 to 218 in 3b220e0
which_path =
"C:\\Git\\rust\\nushell\\typos.toml"nushell/crates/nu-command/src/system/run_external.rs
Lines 219 to 221 in 3b220e0
command_name = "./typos.toml"does not equalfile name = "typos.toml"nushell/crates/nu-command/src/system/run_external.rs
Lines 222 to 230 in 3b220e0
cmd =
"cmd" "/D" "/c" "typos.toml"and then the child spawn successfully
input =
typos.tomlnow this one is kinda funny, it fails because
./is missing which means the command name is equal to the file name, and we don't spawn another processwe get to this
ifand stop:nushell/crates/nu-command/src/system/run_external.rs
Lines 219 to 221 in 3b220e0
command_name = "typos.toml"equalfile name = "typos.toml"19 remaining items
fdncred commentedon Nov 12, 2024
Hopefully this fixes the problem. It does for me.
#14318
youk commentedon Nov 12, 2024
Hey, that was quick! Thank you.
allow nuscripts to be run again on windows with assoc/ftype (#14318)
Araxeus commentedon Nov 15, 2024
This wasn't actually fixed and is an undocumented regression.
fdncred commentedon Nov 15, 2024
Executing nushell scripts should be fixed. Executing bat and cmd seems to work fine. Executing ps1 may not be something nushell needs to do without pwsh.exe. Executing text files is definitely not something nushell should do, that relies on windows and the file extension association system. That's what the start command is about.
youk commentedon Nov 15, 2024
I think the problem here is the apparent lack of design. Thus all these maybes and shoulds. When design is unclear the observable behavior becomes the design. As such, I can only agree that this is a regression. The issue shouldn't be closed as if it was resolved. Either it should be reopened, or closed as "won't fix".
fdncred commentedon Nov 15, 2024
We welcome people to come in and design things. However, we can't design everything since we're staffed by a team of volunteers, there are a million little details, and the team mostly does what they're interested in, like any open-source project.
I can ask the core-team if they think ps1 files should be launch-able without specifying pwsh.exe and see what they think, so it's not only me making decisions. We also have weekly meetings that are open to the public that people can join and discuss items important to them.
Side note, if we wanted to execute ps1 files we'd also have to know if the user wants to run powershell.exe or pwsh.exe. I'm not sure how we'd tell that by doing just "./test.ps1".
fdncred commentedon Nov 15, 2024
I'll re-open the issue so we can continue discussing how
.ps1should be handled.fdncred commentedon Nov 15, 2024
If we do allow .ps1 to be easily executed, it opens up the possibility of consuming powershell output pretty easily. I mean the same thing could happen with
powershell -Command 'Get-ChildItem | ConvertTo-Json'but it's a tad bit easier to have a script like below.fdncred commentedon Nov 20, 2024
Closing due to #14379
Let me know if I should reopen for some reason again.
zhruith commentedon Dec 14, 2024
How about .py or .js ?
U:\python> cmd
U:\python>pi
Ellapsed time: 0.07150912284851074 s
number:99495000
U:\python>exit
U:\python> pwsh
PS U:\python> ./pi
Ellapsed time: 0.0743412971496582 s
number:99495000
PS U:\python> exit
U:\python> pi.py
Error: nu::shell::io_error
× I/O error
help: %1 is not a valid Win32 application. (os error 193)