# File.read unexpected error

**URL:** <https://forum.crystal-lang.org/t/file-read-unexpected-error/6855>\
**Category:** Help & Support\
**Created:** [May 20, 2024, 2:10pm UTC](https://forum.crystal-lang.org/t/file-read-unexpected-error/6855 "2024-05-20T14:10:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![robmullr](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/robmullr/32/1113_2.png) [@robmullr](https://forum.crystal-lang.org/u/robmullr)\
**Post date:** [May 20, 2024, 2:10pm UTC](https://forum.crystal-lang.org/t/file-read-unexpected-error/6855/1 "2024-05-20T14:10:21Z")

</div>

I’ve got a C header file (testfile.h) that only has a comment line "/\* comment _/". When I execute “puts File.read(testfile.h)” an error is generated:  
1 | /_ comment \*/  
^  
Error: invalid regex: quantifier does not follow a repeatable item at 0

Using Crystal 1.12.1 on x86\_64-pc-windows-msvc

This is not expected behavior, shouldn’t it simply read the characters and return the string? If I wanted regex processing, I’d tell it to.

Any explanation or work around appreciated.

---

<div class="post-metadata">

**Author:** ![beta-ziliani](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/beta-ziliani/32/1821_2.png) [@beta-ziliani](https://forum.crystal-lang.org/u/beta-ziliani)\
**Post date:** [May 20, 2024, 3:54pm UTC](https://forum.crystal-lang.org/t/file-read-unexpected-error/6855/2 "2024-05-20T15:54:59Z")

</div>

Just to be sure, you have a file `testfile.h` with

```c
/* comment /

```

And another file, say `test.cr`, with

```cr
puts File.read("testfile.h")

```

and you execute `crystal test.cr` and it fails?

---

<div class="post-metadata">

**Author:** ![robmullr](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/robmullr/32/1113_2.png) [@robmullr](https://forum.crystal-lang.org/u/robmullr)\
**Post date:** [May 20, 2024, 5:35pm UTC](https://forum.crystal-lang.org/t/file-read-unexpected-error/6855/3 "2024-05-20T17:35:54Z")

</div>

Hmm, that case didn’t work earlier but now it does.

I’ve recreated the issue using an ARGV[0] input. The test.cr file is one line:

`puts File.read(ARGV[0])`

and is in the same directory as the testfile.h.

When executed using

`crystal run test.cr testfile.h`

it responds with the invalid regex error.

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [May 20, 2024, 6:42pm UTC](https://forum.crystal-lang.org/t/file-read-unexpected-error/6855/4 "2024-05-20T18:42:33Z")

</div>

When you pass multiple paths to `crystal run` they are all treated as source files. So the compiler tries to read `testfile.h` as Crystal code (which it is not). If you want to pass options to the compiled program, you need to separate them with `--`: `crystal run test.cr -- testfile.h`
