Perl/C issue

  • black_cat666
  • Born
  • Born
  • black_cat666
  • Posts: 4

Post 3+ Months Ago

I'd like to know how I can launch a C++ program in a Perl script.
In fact, I can only use the .c file.
How can I compile it in Perl? Am I obliged to use Perl module like XS?
Because my script should be use by a lot of persons and so I'd like to avoid manual actions (like installation or compilation)...

Any comments are welcome!!!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

You have to compile the .c into an executable binary file before you can use it. Therefore, you or the final user of the C file will have to compile it, before it can be executed from the Perl script. Then, you have the system() function in Perl to call a program.
  • black_cat666
  • Born
  • Born
  • black_cat666
  • Posts: 4

Post 3+ Months Ago

Is there no way to do all these steps in Perl?

Because I'd like to avoid manual actions.

A know there is a way to compile C in Perl, but I can't find how...

Thank you for your help !!
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

Well, I don't know what you mean about compile C in Perl. If you mean running the C compilation utility, of course you can. But the final user will have to install a lot of developer tools in its system. Besides, it makes no sense.

If you mean putting C source code into Perl and make it work, you can't.
  • black_cat666
  • Born
  • Born
  • black_cat666
  • Posts: 4

Post 3+ Months Ago

To be clearer: all the users of my script have Visual C++ Studio on their PC, so there is no installation needed (to compile the C programs).

To answer your question, I just want to have one script that can do all the tasks I want. I know that I can make a package with several files (the .exe files...) but I'd like to avoid that.

You seem to tell you can manipulate Visual C++ with Perl, how do you perform that? Like Microsoft office, for example?

As I don't know much about C, I don't really know how I can use one C function practically. I mean which steps I have to do so my C program is executed.
I thought you just have to compile and execute the C code...

Pease correct me, if i'm wrong...

A real thankyou for your help!!
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

Quote:
I thought you just have to compile and execute the C code...

Well, you are right from a particular point of view. That all you have to do. BUT, an .EXE file is a functional UNIT so you won't have access to particular functions inside the EXE from Perl. All you will be able to do is call the .EXE passing commandl line arguments and (at most) send signals to the process in the operating system.

But, for you (from Perl), that .EXE file which you compiled and any other .EXE file (whose sources you do not know) is just the same.

I keep thinking you don't know much about the subject and you are getting the wrong idea about the best solution for your problem. Please, don't you take it like offense. I guess you need to be sure you are going the best way to solution. Time is money.
  • black_cat666
  • Born
  • Born
  • black_cat666
  • Posts: 4

Post 3+ Months Ago

You're completely true when you're saying that I don't know much about this subject; If it was the case, I don't think I will need any help!

But I don't think this is impossible to understand, so if you think you've got the right idea, please explain it to me...

Because I'm still thinking I don't have the complete process...

Don't be afraid of offensing me, I'm aware of my level in programmation...
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

Well, offensing is not the idea.

Let's see, you said the end-user got VC++ installed in its computer. Then, I must be right supposing the all end users share the platform: Windows.

For a C or C++ program, you (as developer or system administrator) have to compile the source code for all platforms where you need the program executed generating an executable file for the platform (.EXE for Windows). In this case, I guess one single compilation will do. Once you have the .EXE file, you must install the program in the end-user computer: by yourself (if you have access to the computer) or by using an Installation utility builder as NSS, InnoSetup, etc.

With the C program compiled and installed in the computer and accesibles by PATH environment variable or knowinf the full installation path. You will be able to execute the program from Perl using the system() function. You will be able to pass parameters using the command line and you will be able to know about the exit code by inspecting the value returned by the system() function.

Your Perl script will wait for the C program to end before executing the line of code comming next to the system() function call.

Code: [ Select ]
#Perl sample code for executing ipconfig.exe located (for WinXP in C:\WINDOWS\system32)

print("Ok, let's see the IP configuration:\n\n");
system("ipconfig /all");
print("\nDone.\n\n");
  1. #Perl sample code for executing ipconfig.exe located (for WinXP in C:\WINDOWS\system32)
  2. print("Ok, let's see the IP configuration:\n\n");
  3. system("ipconfig /all");
  4. print("\nDone.\n\n");


Now, if you feel this is not the solution you need. You should think about replacing the C / C++ code using Perl. That way you will be putting the C program functionality into the Perl script and you won't need to bother about C and the compilation/installation issue. Which I don't see as a real issue.

For more help, I think you will have to explain the purpose of your Perl script and the C application in detail.

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 75 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.