So I have been loving CodeBlocks (13.12 now) for a few years now and Linux (mint16) for a few months.
Any ways I'm trying to get a program to put a string onto my main clipboard, which I can do fine from a terminal with something like:
~ $ echo "This Text TEST" | xsel -i -b
Which puts "This Text TEST" on the clip board. So when I write this to the terminal from C using the code:
int main()
{
system("echo \"This Text\" | xsel -i -b");
return 0;
}
it puts "This Text" on the clipboard as expected and the program exits as expected. But then I can't re-run the program until I copy some other text. By can't re-run I mean the green 'build and run' arrow is still grey. http://imgur.com/d1mLElr but the second I copy some random text 'build and run' comes alive again. So what is really running that little run arrow? I 'Press ENTER to continue.' and nothing. any Ideas, Thanks in advance
I got something working so for completeness I will post. I found that 'xclip' was very similar and would not hang up C::B, but now the data is not retained in the clipboard after ending the program, but that is better for development. here is my function to put time and voltage data on the clipboard so I can paste it into a 'CSV Voltage Source' in https://www.circuitlab.com/
#define ClipBoardDataFile "../../ClipBoardDataFile.txt"
/// sudo apt-get remove xsel
/// Needed to install xsel
/// Help from http://linux.die.net/man/1/xclip
/// and http://www.hashbangcode.com/blog/using-xclip-copy-output-command-line-linux
/// Puts data set from T and V into main clip board so it can be easily
/// pasted into a CircuitLab.com CSV element
void CLCSVtoClipBoard(size_t N, double T[N], double V[N])
{
FILE *fp;
int k;
char SystemCommand[128];
fp = fopen(ClipBoardDataFile, "w"); // Open temp file for data
// Put data into temp file //
fprintf(fp, "%lf , %lf", T[0], V[0]);
for(k=1;k<N;++k)
fprintf(fp, "\n%lf , %lf", T[k], V[k]);
fclose(fp); // Close temp file for data
usleep(100); // Pause for just a moment
/// System command to put fine data into main clipboard ///
sprintf(SystemCommand, "xclip %s -selection c", ClipBoardDataFile);
system(SystemCommand);
usleep(100); // Pause for just another moment
printf("Paste data before ending program\n");
fflush(stdout);
remove(ClipBoardDataFile); // Delete temp file for house keeping
return;
}
#define CLCSVtoClipBoard(T, V, N) CLCSVtoClipBoard(N, T, V)
#define L 100
int main()
{
int k;
double Time[L], Voltage[L];
for(k=0;k<L;++k)
{
Time[k] = k / 100.0;
Voltage[k] = sin(k/40.0);
}
CLCSVtoClipBoard(Time, Voltage, L);
return 0;
}