Copy from command line automatic

I have written a small program, where i need to output from the command line to be copied to the clipboard automatic. Can that be done? I'm working on a windows

source code:

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
int usernum;
printf("Indsaet de 4 cifre nu");
scanf("%d", &usernum);

switch(usernum){
case 1234:
printf("123456");
break;
case 5678:
printf("7891011");
break;
default:
printf("Tjek at de indsatte cifre er rigtige og proev igen");
}
system("ping -n 120 127.0.0.1 > NUL");
return 0;
}
It can be done, but you are in for a world of hurt.

Perhaps you ought to take a look at Tcl/Tk, which can do it much more easily for you.
http://www.tcl.tk/

In either case, you have got a lot of learning ahead of you. (Sorry.)
Duoas is right based on your question. But I suspect that you are ignoring your Operating System the tools at your disposal a little too much. I have a few questions that may save you a headache in the long run, especially if the security suite is set up right.

- Tell us, do you know what data piping is? If so would this be a better solution? If not I can explain.

- When Windows opens a file, it passes the name of the file to the program associated with its extention. For example when you open "SomeThing.txt" Windows passes that string to notepad.exe so if you were to do the same thing on the command line it would look something like this notepad.exe SomeThing.txt, yes there is more to it but let's not confuse the OP. This string is part of the first and\or second argument to CreateProcess(...), or the argv[1] argument in you code above. Could this be used to pass your data to it's destination?

- (I shutter to ask this one because it is a 'hack' solution) Could your data be written into a text file, then read from that file by the intended destination?

EDIT: It occures to me that if you take the scholars route and start reading everything you can pull up on your browser that the first command you will come across to fulfill your need is "CLIP" for the Windows 7 SDK. Please DO NOT USE THIS SOLUTION! You should not have to rely on any System calls, even if you are using the correct API commands such as CreateProcess, to accomplish something like this in C++. It's a bad habit, and becomes hard to break.

I guess the point of my post is to lure you away from using the clipboard at all.
Last edited on
I have read a bit about data piping, and I did try that at first, but I couldn't get it to work. The output have to go onto a website field. I was trying to get it to also do that, but I quickly found out that I'm to much of a beginner to do that. I would like not to use the last example. I would like to know how data piping would work, if you could explain it to me? I just need to figure out the easiest solution on how to get the output from the command line to the website as easily and automatic as possible for the user :)


Douas, thank you so much for you answer - I will look into that :)
Last edited on
Go with Duoas suggestion. Sorry friend, the very little bit I know about that stuff is %100 non-standard and all blackhat purposed it's not something I'll discuss on this site out of respect. I can tell you a few things to get you started.

- First of all, the language that the site is written in will determine how you shape you code. If it's written in Java then you'll be piping your data into a function, if it's SQL then you'll be modifying the data in the address bar if it's HTML, you'll be looking for the approprate link within the code of the file etc. etc. Ad Infinum. You have to know the language better then the author, or at least hope he's lazier then you.

- Second, Start -> Run -> cmd -> explorer http:\\www.google.com that is all
Last edited on
You will have to pipe the results of the ping command either way. It is just much easier to do that in Tcl than C++. It is also much easier to play with the clipboard with Tcl.

You'll need this site for reference:
http://www.tcl.tk/man/tcl8.5/

You'll need the open (Tcl) and clipboard (Tk) commands.
Topic archived. No new replies allowed.