Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8536055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:34:28+00:00 2026-06-11T10:34:28+00:00

Can you tell me why this code gives an error? I am not understanding

  • 0

Can you tell me why this code gives an error?

I am not understanding this line: File.new("#{line}", "w")

system "ipconfig /all > info.txt"
info_text = File.open("info.txt")
info_text.each { |line|
  if line =~ /Physical Address/
    line.slice! "   Physical Address. . . . . . . . . : "
    File.new("#{line}", "w")
  end
}

Thanks -Mike W

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:34:29+00:00Added an answer on June 11, 2026 at 10:34 am

    The code is designed to run on Microsoft Windows. The script won’t do anything useful on other OSes. In particular, it tries to create one empty file for every Network Adapter on your system, using the MAC address.

    It’s very likely that line contains a character that Windows doesn’t allow in a filename. (Windows is more restrictive than Linux or Mac OS X.) What’s the error you’re getting?

    Also, try printing the line variable immediately before calling File.new to see what it contains.

    You probably need to sanitize line by removing invalid characters. See this answer for what isn’t allowed. The easy way would be to use a simple whitelist:

    # remove non-alphanumeric and non-underscore
    line.gsub!(/\W/, '')
    

    I suspect that it’s the newline that’s causing the error.

    UPDATE:

    I did a test on Windows and it’s indeed the carriage return (\r) and line feed (\n) that cause the problem. I get Errno::EINVAL: Invalid argument.

    This should fix it, by removing all whitespace:

    line.gsub!(/[\s]/, '')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you please tell me why this line of code gives error:- Object reference
Can anyone tell me why this code would not be working? $('body').on('test', function() {
Can anyone tell me what's wrong with this code? It's giving me an error
Can someone please tell me whats wrong with this code. I'm not getting complete
can anyone tell me why this code don't work: $q = $_GET['q']; // Load
As far as I can tell, this code is fine, and should display some
Can anyone tell me what's wrong with this code? class Dataset < ActiveRecord::Base has_many
Can someone tell me what is wrong with this code? <?php $user = $fgmembersite->UserFullName();
Can anyone tell me what is wrong with this code? public abstract class BoardTestBean{
I can't tell if this is a bug or what. The following code works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.