Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

unix2dos command in perl script

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am writing a perl script to call unix2dos command from a perl script to ensure that each line in a file will end with a carriage return and new line using following command.

system("unix2dos <filename>");

I have also tried executing the following command in perl script.

system("perl -i -p -e 's/\n/\r\n/' <filename>" );

but it is not giving the desired results.

OS is linux. Do we have to check any OS compatability to use above mentioned commands? Please suggest on this.

Thanks & Regards,
Susmitha.



 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a little confused. Why is a Perl script needed for this? Why not just invoke unix2dos directly instead of via the Perl script?

P.S. It is almost trivial to write the equivalent of unix2dos in Perl without the need to invoke unix2dos using system().
P.P.S. Though I don't understand the need for this I suspect you need
where $file contains the filename.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Susmitha Metlapalli wrote:
I have also tried executing the following command in perl script.

system("perl -i -p -e 's/\n/\r\n/' <filename>" );


Maybe I'm misunderstanding something, but are you really calling an external command to run a perl script from within a perl script there? Why not just run the perl commands directly?
 
Susmitha Metlapalli
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have to run this perl script as a cronjob.

How to execute the following from within a perl script?

system("perl -i -p -e 's/\n/\r\n/' <filename>" );

I am not getting the desired result...

Is the above syntax same? do we need to declare anything in the perl script? like "use:"


Thanks,
Susmitha.


 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you miss my first reply?
 
Poop goes in a willow feeder. Wipe with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic