diff --git a/src/main/java/org/perlonjava/core/Configuration.java b/src/main/java/org/perlonjava/core/Configuration.java index 1c8294666..5d718bcd5 100644 --- a/src/main/java/org/perlonjava/core/Configuration.java +++ b/src/main/java/org/perlonjava/core/Configuration.java @@ -33,7 +33,7 @@ public final class Configuration { * Automatically populated by Gradle/Maven during build. * DO NOT EDIT MANUALLY - this value is replaced at build time. */ - public static final String gitCommitId = "4aafb6057"; + public static final String gitCommitId = "a7261e446"; /** * Git commit date of the build (ISO format: YYYY-MM-DD). diff --git a/src/main/java/org/perlonjava/runtime/operators/IOOperator.java b/src/main/java/org/perlonjava/runtime/operators/IOOperator.java index 97dc2d33d..3ad8c7349 100644 --- a/src/main/java/org/perlonjava/runtime/operators/IOOperator.java +++ b/src/main/java/org/perlonjava/runtime/operators/IOOperator.java @@ -734,6 +734,14 @@ public static RuntimeScalar print(RuntimeList runtimeList, RuntimeScalar fileHan try { // Write the content to the file handle return fh.write(sb.toString()); + } catch (java.nio.channels.NonWritableChannelException e) { + // Writing to a read-only filehandle (opened with "<") + getGlobalVariable("main::!").set("Bad file descriptor"); + WarnDie.warnWithCategory( + new RuntimeScalar("Filehandle opened only for input"), + new RuntimeScalar(""), + "io"); + return new RuntimeScalar(); // undef } catch (Exception e) { getGlobalVariable("main::!").set("File operation failed: " + e.getMessage()); return scalarFalse; @@ -779,6 +787,14 @@ public static RuntimeScalar say(RuntimeList runtimeList, RuntimeScalar fileHandl return scalarFalse; } return fh.write(sb.toString()); + } catch (java.nio.channels.NonWritableChannelException e) { + // Writing to a read-only filehandle (opened with "<") + getGlobalVariable("main::!").set("Bad file descriptor"); + WarnDie.warnWithCategory( + new RuntimeScalar("Filehandle opened only for input"), + new RuntimeScalar(""), + "io"); + return new RuntimeScalar(); // undef } catch (Exception e) { getGlobalVariable("main::!").set("File operation failed: " + e.getMessage()); return scalarFalse;