Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Back Ticks - can't get it to work.

Back Ticks - can't get it to work.

Back Ticks - can't get it to work.

I have a script which executes a doc to pdf conversion on my windows server. I originally used a command line switch on Open Office to do the conversion, and this worked, but the PDF created is poor.

I am now using word and OfficeToPDF.exe.

The command required (that works perfectly on the command line) is d:\officetopdf\officetopdf.exe /print d:\test.docx d:\test.pdf
This creates the PDF perfectly.

Trying to execute this is perl, and I run into trouble.

This executes and returns no error, but I have no arguments.

$cmd = "d:\\officetopdf\\officetopdf.exe /print";

This wont execute and returns an error of 256 in $?.

$cmd = "d:\\officetopdf\\officetopdf.exe /print d:\\officetopdf\\a.docx d:\\officetopdf\\a.pdf";

I have tried all sorts to get this going, and am just not succeeding.

I have tried just file names with no path. If I print $cmd to screen, copy and paste the line, and then paste it into the command prompt, it executes, so the double \\ are doing their job and escaping the 'true' one.

Any ideas?


RE: Back Ticks - can't get it to work.

Couple thoughts:
1 - Your assignment $cmd = "d:\\xxx\\yyy" ;
Will translate into d:\xxx\yyy in $cmd. Then when you use `$cmd` it is looking at d:\xxx\yyy and will again translate the \x and \y into their equivalent escape characters. Try using single quotes on the initial $cmd = 'd:\\xxx\\yyy' ; Then the `$cmd` should behave cleaner for you.

2 - If you have access to the perl cookbook - look up their method of using system() to make a call to the OS. Since I can find this online in various places, I'll reprint here but I recommend getting the book. There are some really elegant routines in there


$rc = 0xffff & system @args;
printf "system(%s) returned %#04x: ", "@args", $rc;
if ($rc == 0) { print "ran with normal exit\n";
} elsif ($rc == 0xff00) { print "command failed: $!\n";
} elsif (($rc & 0xff) == 0) {
    $rc >>= 8;
    print "ran with non-zero exit status $rc\n";
} else {
    print "ran with ";
    if ($rc &   0x80) {
        $rc &= ~0x80;
        print "coredump from ";
    print "signal $rc\n"
$ok = ($rc == 0); 
I've added bells-n-whistles to this basic routine to have it give me a call-stack trace to help debug longer calling paths. But the above should get you started. My apologies to Mr. Torkington and Mr. Christiansen if I've wrongfully posted their code here. FWIW - That book and the Advanced Perl have helped me write code libs much more efficiently.

RE: Back Ticks - can't get it to work.


Thank you.

I cannot even get system() to work - I just get a 502 error from iis when trying to include a call that way. I struggled with it previously, which is why I ended up using the backticks method instead. That did work fine with the call to Open Office. Not sure why it's not working with this command.

RE: Back Ticks - can't get it to work.

Taking a swag here ... Does


$cmd = "d:\\\\officetopdf\\\\officetopdf.exe /print"; 
work? (Using 4 backslashes) Try dumping $@, $! and $^E as well. May give more insight.

RE: Back Ticks - can't get it to work.


If I execute that command with no arguments, I get the below returned:

$? = 0
$^E = An operation was attempted on something that is not a socket
$! - null
$@ - null

With the arguments added:

$? = 256
$^E = An operation was attempted on something that is not a socket
$! - null
$@ - null

I then realised I can grab the output of the shell command as a variable:

$output = `$cmd`;

This outputs:

Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)). Did not convert

So I guess I have a problem with permissions - But I am not sure what permissions I need here for IIS? It is an authenticated website, using windows basic authentication (over SSH), so I assumed as long as the user had permission on the folder, it would be fine. I tried giving IUSR permission too....

RE: Back Ticks - can't get it to work.

Thinking back, I have seen that sort of thing before - the system call executes under a different set of credentials. At a command prompt I tried 'help start' and 'help cmd' and neither of them showed references on how to supply a user/password in the calling sequence to potentially reset your permissions. Sooo - another idea just to see if you can get something to work: Ever use PsTools or Sysinternals (they're effectively the same program)? I won't plug a website here but it's easy enough to find. Anyway there is a routine in there called PsExec.exe which you can specify a \\computer -u<user> -p<password> and a <command>. I've used this to run program installs on remote computers. I've had the best luck if I have the perl program build a .bat file under the system32 directory of the target computer then call the .bat file using the PsExec command. I realize this is getting way more complicated than what originally started out as a simple $cmd = xxx ; `$cmd` sequence.

Out of curiosity, is the officetopdf.exe making a call out to a web site? If your network does not support anonymous calls out to the web, that could be the source of the socket error. Maybe try a $output = `whoami` ; and see what that gives back. Is that the user you expect? Sorry I'm not much more help at this point.

RE: Back Ticks - can't get it to work.


officetopdf.exe is just a third party plugin which uses MSword to convert a document to a pdf. It works headless, using MSword to do the work.

All my documents, and MSword are on the server (I know putting word on there is not ideal!).

I sorted this out by amending the permissions in the "dcomcnfg -32". Searched for Office, right clicked properties, and security. I originally added iis_users and IUSR, but then realised I needed to add local user accounts (all users), as the website is authenticated, so it required those users permissions set.

All working now smile

RE: Back Ticks - can't get it to work.

A bit late here and it doesn't really solve your problem, but it's worth mentioning anyway - to make your life easier you can use forward slashes in paths for windows and not have to worry about escaping.

For the sake of executing commands in cmd,


$cmd = "d:\\officetopdf\\officetopdf.exe /print"; 
is the equivalent of


$cmd = "d:/officetopdf/officetopdf.exe /print"; 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close