mkdir() function versus mkdir command

Posted on 2014-12-04
Last Modified: 2014-12-20

system("mkdir dir_name");

Open in new window

does not create any folder but,
mkdir("dir_name", 0770);

Open in new window

successfully creates

Question by:Nusrat Nuriyev
LVL 40

Expert Comment

ID: 40480827
Are you capturing error messages? Are you using full path name while calling mkdir?

Author Comment

by:Nusrat Nuriyev
ID: 40482444
Are you using full path name while calling mkdir?

how to capture?
LVL 40

Accepted Solution

omarfarid earned 500 total points
ID: 40483786
try to redirect the errors to a file:

system("mkdir dir_name > /tmp/mylog 2> /tmp/myerror");
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

LVL 48

Expert Comment

ID: 40485916
As per the system documentation, use:

@args = ("mkdir", "/path/to/dir");
system(@args) == 0 or die "system @args failed: $?"

Open in new window

LVL 84

Expert Comment

ID: 40485960
Is this written in Perl or C?
LVL 48

Expert Comment

ID: 40486052
Whoops.  Didn't see the topics.   My last post is for Perl only.

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

813 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

11 Experts available now in Live!

Get 1:1 Help Now