473,503 Members | 1,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to incorporate variable data in system call?

1 New Member
I'm a newbie with Perl. I'm trying to make a system call to move some files to another directory, but the directory is based on a variable that I've created.

Here is a snippet of my code:

Expand|Select|Wrap|Line Numbers
  1. my $newsubdir = $dir . $filedate;
  2. mkdir($newsubdir,0777) || die "cannot mkdir";
  3.  
  4. system("move C:\\test\\files\\*.log  C:\\test\\files\\$newsubdir\\");
  5.  
The $newsubdir doesn't seem to work inside the system call.. Can someone tell me what I'm doing wrong? Thanks in advance! :)
Dec 4 '07 #1
5 1673
numberwhun
3,509 Recognized Expert Moderator Specialist
I'm a newbie with Perl. I'm trying to make a system call to move some files to another directory, but the directory is based on a variable that I've created.

Here is a snippet of my code:

Expand|Select|Wrap|Line Numbers
  1. my $newsubdir = $dir . $filedate;
  2. mkdir($newsubdir,0777) || die "cannot mkdir";
  3.  
  4. system("move C:\\test\\files\\*.log  C:\\test\\files\\$newsubdir\\");
  5.  
The $newsubdir doesn't seem to work inside the system call.. Can someone tell me what I'm doing wrong? Thanks in advance! :)
Have you tried doing a print of the $newsubdir variable to ensure that it is getting set correctly? We don't have the rest of your code and I don't like making assumptions.

Regards,

Jeff
Dec 4 '07 #2
new1234
2 New Member
Hi, I'm actually having the same problem..
when I run:
Expand|Select|Wrap|Line Numbers
  1. print "making directory ";
  2. print $directory;
  3. print "\n";
  4.  
  5. mkdir($directory,0777) ||  print $!;
  6.  
I get the output 'No such file or directory'.
I've tried this:
Expand|Select|Wrap|Line Numbers
  1. print "making directory ";
  2. print $directory;
  3. print "\n";
  4. $directory="\"".$directory."\"";
  5. print $directory;
  6. print "\n";
  7. mkdir($directory,0777) ||  print $!;
  8.  
Error = No such file or directory
and this:
Expand|Select|Wrap|Line Numbers
  1. mkdir("$directory",0777) ||  print $!;
  2.  
which creates the directory ./$directory ...
As you can see I've been checking that the variable prints out correctly. (Output for the first snippet of code is: "making directory ./testdir/testdir2/")
Any help would be really appreciated..
Dec 20 '07 #3
new1234
2 New Member
I think it's because I may or may not have subdirectories that I want to make too - I caved and used
Expand|Select|Wrap|Line Numbers
  1. system "mkdir -p $directory" ||  print $!;
  2.  
which works very nicely.. I'd still be interested in any alternative solutions as this seems a bit clumsy to me.
Cheers
p.s. i'm also struggling to remove the ./$directory that i created above (oops). Command line returns "directory: Undefined variable" I've tried hashing out the $
rm \$directory
and
rm "$directory"
--> same result.. d'oh!
Dec 20 '07 #4
numberwhun
3,509 Recognized Expert Moderator Specialist
I think it's because I may or may not have subdirectories that I want to make too - I caved and used
Expand|Select|Wrap|Line Numbers
  1. system "mkdir -p $directory" ||  print $!;
  2.  
which works very nicely.. I'd still be interested in any alternative solutions as this seems a bit clumsy to me.
Cheers
p.s. i'm also struggling to remove the ./$directory that i created above (oops). Command line returns "directory: Undefined variable" I've tried hashing out the $
rm \$directory
and
rm "$directory"
--> same result.. d'oh!
Question, are you just wanting to print the error if it doesn't work? It is more customary to use the die() function for that and not just a print statement. That way, processing can be stopped at point of failure.

Regards,

Jeff
Dec 20 '07 #5
KevinADC
4,059 Recognized Expert Specialist
this looks wrong:

$directory="\"".$directory."\"";

why do you want to add double-quotes around $directory? If $directory were: foo/bar it would equal "foo/bar" after being processed by the above line.
Dec 20 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1897
by: Rob | last post by:
Please recommend best practice for adding a global variable to an ASP.net class that will take on a Request.Params("") value from the URL calling the aspx page to be used throughout in stored...
5
3882
by: The Beast | last post by:
I'm trying to create a thread to write to the serial port and I keep getting an odd error cannot convert parameter 3 from 'unsigned long (void *)' to 'unsigned long (__stdcall *)(void *)' and...
1
1488
by: DC Gringo | last post by:
I am trying to pass an input parater to SQL Server. The parameter is a URL querystring variable. I can't seem to get it to pass a variable, only a literal value... Help! In the following...
9
3120
by: Shapper | last post by:
Hello, I am declaring a variable in my aspx.vb code as follows: Public Class catalogue Public productid As String Private Sub Page_Load ... I have an image button where I call the...
7
2177
by: Aaron | last post by:
Complete code follows. I am new to .NET programming (and programming in general) and I am having a difficult time understanding how to fill a variable in one sub, and then access it from...
1
3848
by: John_H | last post by:
Re: ASP.NET 2.0 I would like suggestions or code examples on how to collect a variable length list of input data (item# & item quantity specifically). I thought that I could accomplish this...
6
3318
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in...
0
951
by: =?Utf-8?B?bWFydGluMQ==?= | last post by:
I just use queryString ("image") to keep generated chart in the middle panel with top menu and bottom table when user select different chart varibale like Unit on the dropdownlist button and enter...
3
1000
by: Saul Spatz | last post by:
Hi, I'm making a project into my first package, mainly for organization, but also to learn how to do it. I have a number of data files, both experimental results and PNG files. My project is...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7087
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6993
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5579
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
737
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
383
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.