Solved

Redirect output to file in subdirectory

Posted on 2008-06-10
4
1,210 Views
Last Modified: 2008-06-10
I have a problem with a perl script that should redirect output to a certain file in a certain directory. The problematic line is
system "echo teststring >$testdir\\log.txt";

This is running on Windows 2000.

Changing the line to just
system "echo teststring >log.txt";
works fine, but when a subdirectory is specified, the file is never created and I don't get any output at all.

0
Comment
Question by:loveslave
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 21749487
what is in $testdir, and how was it set?
0
 
LVL 1

Author Comment

by:loveslave
ID: 21749546
Sorry, I should have said that from the beginning.
The value of $testdir doesn't seem to matter. Even if I do

system "echo teststring >Test\\log.txt";

I get the same error (no output, no file is created). In this case, Test is an existing subdirectory of the directory from where I call the perl script.

If I make the same call at a command prompt (echo teststring >Test\\log.txt) I get the desired result.
0
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 21749602
did you try
system "echo teststring >Test\\\\log.txt";
0
 
LVL 48

Expert Comment

by:Tintin
ID: 21749645
Why not just do it in Perl, eg:


open LOG, ">Test/log.txt" or die "Can not write to Test/log.txt $!\n";

print LOG "teststring\n";

close LOG;

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how do I grep for a specfic DNS record in a directory 3 42
Perl strange behaviour 5 69
Perl Application JSON Receiving Strange Java Error 3 67
Export Variables in Perl 3 46
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now