473,516 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

execute command line arguments

please let me know

if am using command line arguments, how to send arguments to a C
program if i am working on ubuntu

say for example
suppose name of my program is prog.c
if argc=3
then how to send those three arguments(pt1.txt,pt2.txt,pt3.txt) to
prog.c through command prompt if i am working on linux

please reply urgently
Feb 24 '08 #1
4 2971

<ne**********@yahoo.co.inwrote in message
news:6a**********************************@e25g2000 prg.googlegroups.com...
please let me know

if am using command line arguments, how to send arguments to a C
program if i am working on ubuntu

say for example
suppose name of my program is prog.c
if argc=3
then how to send those three arguments(pt1.txt,pt2.txt,pt3.txt) to
prog.c through command prompt if i am working on linux

please reply urgently
typer

int main(int argc, char **argv)

argc is the number arguments the user typed onm the commandline. Argv is an
array of those arguments, this is to say argv[0] is the name of the program.
argv[1] the first argument, argv[2] the second, and so forth.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Feb 24 '08 #2
ne**********@yahoo.co.in wrote:
please let me know

if am using command line arguments, how to send arguments to a C
program if i am working on ubuntu

say for example
suppose name of my program is prog.c
if argc=3
then how to send those three arguments(pt1.txt,pt2.txt,pt3.txt) to
prog.c through command prompt if i am working on linux

please reply urgently
We are not your contract workers. We try to help but we cannot help you
with your last minute problems.

If your program executable is named 'prog', to give it the arguments
pt1.txt, pt2.txt and pt3.txt do at the command prompt and with the
programs's directory as your working directory:

prog pt1.txt pt2.txt pt3.txt

The general formula is:

PROGRAME [ARG 1] [ARG 2] [...]

You first type the program's name, as you would for any other program
and then type out it's arguments one after the other, separated by a
space. This will do fine for starting out. Later on you might like to
write a general purpose arguments processor along the lines of getopt
and others that handle more complicated formats and conditions.

PS. Note that in the example above argc will be four, not three, as the
program's invocation name also counts as a parameter, a difference from
languages like Java.

Feb 24 '08 #3
ne**********@yahoo.co.in wrote:
>
say for example
suppose name of my program is prog.c
if argc=3
then how to send those three arguments(pt1.txt,pt2.txt,pt3.txt) to
prog.c through command prompt if i am working on linux
This is a questoin about how to use the linux shell. You should ask in a
linux group.
However you can probably find out the answer very much quicker by
examining any of the hundreds of shell scripts that will be on your
linux box. Many of them will invoke programmes such as sed, grep, awk
and so on with arguments.
Feb 24 '08 #4
On Feb 24, 5:36 pm, neha_chha...@yahoo.co.in wrote:
if am using command line arguments, how to send arguments to a C
program if i am working on ubuntu

say for example
suppose name of my program is prog.c
if argc=3
then how to send those three arguments(pt1.txt,pt2.txt,pt3.txt) to
prog.c through command prompt if i am working on linux

prog.c is an odd name for an executable, but if that's
really what you have, you probably want to execute:

$ ./prog.c pt1.txt pt2.txt pt3.txt

This gives you argc == 4, argv[0] == "./prog.c",
and argv[i] == "pt$i.txt" for i in [1,2,3].

If you really want argc == 3, you could try:

$ ln -s prog.c pt1.txt && PATH=$PATH:. pt1.txt pt2.txt pt3.txt

or something like that.
Feb 24 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2050
by: tom | last post by:
Problem: In PHP, need to execute a program in (freebsd terms) /usr/local/bin in meta-terms: int i; i = (arguments); There seems to be quite a few execution methods in PHP (sorry in advance for being thick), and, er, I was wondering if someone could give me a quick pointer to appropriate ones I should study to:
4
9873
by: Kartik | last post by:
Hi, I have an ASP.NET application using VB.NET.I am sending a DOS command to a machine on the network to print a file. This is achieved using xp_cmdshell Dim str As String = "xp_cmdshell ""type " & nwkfilepath & " > " & pPrinterName & " """
4
7862
by: Chris | last post by:
I posted this in the C# language group, then thought it might be more appropriate in this group. I would not cross-post except I want the answer so badly. I built small C# Web and Web Service applications in a training class last week. The applications worked in the class, but when I tried to run them again over the weekend, they both...
6
5991
by: PAPutzback | last post by:
The process and execute methods want a path to the executable otherwise they kick out a file not found. So how can I execute the following. It works fine from a command window. echo password| gpg.exe --yes --output c:\working\inbound\test.txt --passphrase 0 -d c:\working\inbound\anstest.gpg
1
7879
by: amirmira | last post by:
I would like to set command line arguments to a service at install time. I need to do this because I need to get information from different registry locations depending on my command line argument. I have to do it this way as the consumer of the service should not be able to change the argument - except by uninstalling and reinstalling the...
0
2264
by: Elroyskimms | last post by:
I need to execute a batch file via ASP.Net. In my VB.Net code, I'm using System.Diagnostics.Process to call the batch file and its appropriate command line arguments. I'm using System.Diagnostics.Process.StandardError and System.Diagnostics.Process.StandardOutput to capture and view the output and error messages. My web.config file has the...
1
9479
by: stikhs | last post by:
Hi! I want to execute a command line application through my programme!Is there any instruction that could help me do this?I want to give the arguments via the GUI that I build,so is it possible that i could pass the arguments of the command line programme through my source code? Thanks in advance!
3
6468
by: =?Utf-8?B?S3VlaXNoaW9uZyBUdQ==?= | last post by:
I have a .NET VC++ program, I want to execute some dos command from the program, e.g. copy some file, and etc. How do I do that?
7
9336
by: Jwe | last post by:
Hi, I've written a program which has both a command line interface and Windows form interface, however it isn't quite working correctly. When run from command line with no arguments it should display the Windows form. The form is being displayed but the command only returns when the form is closed. I want the command line to return...
0
7276
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7182
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7408
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7581
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7142
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5714
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3267
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3259
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1624
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.