Is it possible to use a GUI based text editor (e.g. Eclipse) from the terminal? - c

I'd like to use terminal for all of my normal git and compiling and running processes (my school has a server that is linked to my repo on bitbucket), but I really don't like terminal-based text editing software such as Emacs and Vim. Is it possible to open and edit files from the terminal using a GUI based text editor? The reason I'm asking is because the terminal is the only way I can access the server files. Thanks in advance!

Aw, but vim is the best! :) Well, you can use nano, which is friendlier. Or, if you insist: if you are using SSH to connect to the server (and the server has an X server running !) then you can look into the ssh -X option to view X windows on your remote machine.
Oh and you could look into scp command as well (behaves almost just like regular cp, but the destination is on another host). That way you could edit on your machine, then copy it via SSH (although you'd want to be careful when copying files directly to the server filesystem)
Edit: Also, if you really don't like using the terminal (why though? (-: ), some file managers allow you to get the same functionality of the previous commands purely via GUI (for example).

You've left out some important information that someone would need to know to answer your questions. The other posters have made some assumptions.
You've mentioned this "terminal", but it's not clear exactly what that is, or how you're getting to it. What kind of computer do you have in front of you? What shell is running in that terminal? Is the shell running on your local computer, or have you remotely connected to a server and running that shell on the remote computer?
Based on what you said, I have a feeling you're making a remote connection to a server, perhaps using ssh. You likely have either a Windows or Mac PC in front of you. In those circumstances, running a GUI editor like Eclipse is possible, but likely not practical. You would have to have Eclipse installed on that remote computer, and you would be displaying the Eclipse window on your local computer using the X11 protocol. That takes a lot of bandwidth.
If my assumptions are correct, my recommendations depend on how long you expect you're going to want to stay familiar with this environment. If you intend to do this sort of work forever, then you should learn vi and Emacs to the best of your ability. As someone who's been using Emacs likely longer than you've been alive, I'd recommend you learn it, but vi is also a critical skill.

UNIXY systems provide open or gopen, depending on your OS, that should get the job done. From the man page:
By default, gopen will open filename with the application currently assigned to the file's extension. But by specifing the -a flag on the command line you can tell gopen to open the file with another application.
This means that you can use it to open files in your preferred editor
with a line like
gopen -a Eclipse file

Related

How to synchronize code files on windows with WSL/linux?

Basically I have some C/C++ code that I need to build and debug on a Linux machine. Unfortunately, my windows laptop doesn't have enough free hard space to install some Linux dist nor does it have enough free RAM to comfortably run VM.
Until now, I dealt with it rather comfortably using WSL, but the scale was rather small. It was easy to edit and debug 2-3 .c files through CLI and gdb, but it became really annoying on a large scale projects.
I want something simple as "edit code in windows IDE [X], compile it on remote Linux/WSL (the project uses Makefiles), and preferably debug it via gdb".
VS has something close to what I want, but it can't deal with existing Linux projects. It needs to create a new configuration which is alien to the project's Makefile.
I know this question is a bit old, but I think the solution is to make a symlink between your WSL folder and the Window's folder. This is how I handled it for a Ubuntu-20.04 WSL:
Access PowerShell in Administrator mode
Type cmd.exe in the PowerShell
Once cmd.exe is opened, type mklink /d C:\<path_to_your_Windows_folder> \\wsl$\Ubuntu-20.04\home\<your_user>\<path_to_your_WSL_folder>
EDIT
This was tested under Windows 10 Version 2004 with WSL2
I'm unsure about C and C++ but it sounds like this is exactly the same as how i work in node and javascript every day.
I checkout my code using git inside WSL to a location like /mnt/c/code/myproject. Then using sublime/VS code/webstorm i edit the files in windows in the location c:\code\myproject this works really well and have been doing this every day for over a year.
Things to be aware of are that you need to ensure that your editor of choice saves files with linux line endings and that all command line operations are done inside WSL.
Please see this article to see the differences between windows and linux files and how this works inside the WSL.
I want something simple as "edit code in windows IDE , compile it on remote linux/WSL
You will have something as simple as that.
Only with Windows 19.03 though:
See "Updated WSL in Windows 10 version 1903 lets you access Linux files from Windows"
Microsoft's Craig Loewen says:
In the past, creating and changing Linux files from Windows resulted in losing files or corrupting data. Making this possible has been a highly requested and long anticipated feature. We're proud to announce you can now easily access all the files in your Linux distros from Windows.
So how does this work? He goes on to explain:
To put it briefly: a 9P protocol file server facilitates file related requests, with Windows acting as the client.
We've modified the WSL init daemon to include a 9P server. This server contains protocols that support Linux metadata, including permissions.
There is a Windows service and driver that acts as the client and talks to the 9P server (which is running inside of a WSL instance).
Client and server communicate over AF_UNIX sockets, since WSL allows interop between a Windows application and a Linux application using AF_UNIX as described in this post.
Warning:
The old rules still apply, you should NOT access your Linux files inside of the AppData folder!
If you try to access your Linux files through your AppData folder, you are bypassing using the 9P server, which means that you will not have access to your Linux files, and you could possibly corrupt your Linux distro.

Real remote editing without X-Forwarding, using Vim or the like

I'm currently working an a rather large web project which is written using C servlets ( utilizing GWAN Web server ). In the past I've used a couple of IDEs for my LAMP/PHP jobs, like Eclipse.
My problems with Eclipse are that you can either mirror the project locally, which isn't possible in this case as I'm working on a Mac (server does not run on OSX), or use the "remote" view, which would re-upload files when you save them.
In the later case, the file is only partly written while uploading, which makes this a no-go for a running web server, or the file could become corrupted if the connection was lost during uploading. Also, for changing some character, uploading the whole file seems rather inefficient to me.
So I was thinking:
Wouldn't it be possible to have the IDE open Vim per SSH and mirror my changes there, and then just :w (save) ? Or use some kind of diff-files for changes?
The first one would be preffered, as it has the added advantage of Vim .swp files, which makes it possible that others know when someone is already editing the file.
My current solution is using ssh+vim, but then I lose all the cool features I have with Eclipse and other more advanced IDEs.
Also, regarding X-Forwarding: The reason I don't like it is speed. It feels way slower than just editing locally, and takes up unneeded bandwidth, when all I want to do is basically "text editing".
P.S.: I couldn't find any more appropriate tags for the question, especially no "remote" tag, but if you know any, feel free to add them. Also, if there is another similar question, feel free to point it out - I couldn't find any.
Thank you very much.
If you're concerned about having to transmit the entire file for minor changes, the only solution that comes to my mind is running (either continuously, or on demand) an rsync job that mirrors the remote site to your local system (and back). The rsync protocol just transmits the delta information. According to Are rsync operations atomic at file level?, the change is atomic.
Another possibility: run everything in a virtual machine on your Mac. The server and the IDE/text editor are both on the same virtual machine so you don't have to fear network issues.
Because the source code on the virtual machine is under some kind of VCS the classic code → test → commit process is trivial (at least theoretically).

TCP/IP Programming in C

I have an exam on tomorrow on TCP/IP programming. Following is one of the previous question on this paper.
Write and run a client and a server program. Using C language in UNIX, with the
following specifications :
• A TCP client program will send a range of number (e.g. 1 to 10) to the server.
• TCP server accept the number range from client and send back the sum of the
number range. Client will print the result.
I dont know how to setup the compiler and other settings to run this tcp ip programs. When I search online, I got two different programs, one for Client and another For server. Some please tell me how can i run these programs to get desired output. What kind of compiler should I install on my system.( I am using windows 7) ??
Since the assignment requires your code to work on a Unix system, you first need to install one. Follow these simple steps to install a virtual Unix environment on top of your existing Windows installation.
Download and install VirtualBox for Windows.
Download & unpack this Ubuntu 12.10 disc image (NOTE: Requires 7-Zip).
Launch VirtualBox and create a new Virtual Machine (name it Ubuntu).
In the "Virtual Hard Disk" settings, select "Use existing hard disk" and select the image file you just downloaded (NOTE: It's filename should end in ".vdi").
Run your new Virtual Machine. You should see the Ubuntu splash screen.
Login with username ubuntu and password reverse (NOTE: Case Sensitive!).
Open up Terminal and type sudo apt-get install build-essential (NOTE: when Terminal prompts you for a password, use reverse).
You should (with hope) have everything you need for your assignment. For more information on network programming, consult Beej's Guide to Network Programming -- Using Internet Sockets.
You need to open two different terminals on your system.
In the first terminal compile and run the server.c program.(make sure either you listen to all ips or your host ip(atleast).
while this is running.(it will wait for a request from your client program)
Run the client program in the other terminal.
Hope this solves the problem!
For details on how to create and run a file in unix refer http://www.wikihow.com/Compile-a-C-Program-Using-the-GNU-Compiler-%28GCC%29
P.S: you can do the same in win7 if iam not wrong only that terminal here in called command prompt!
Post the results if possible!
Download a thing called VMWare player. And look for a Ubuntu image that you can load with the VMWare player. That way, you will have a little Linux virtual machine that you can run inside or along with Windows 7. You can use the compiler GCC in your Ubuntu or whatever other Linux virtual machine. And get lots of coffee. Blargle is correct, but I think my suggestion is a little better, because you end up having a fairly complete Unix type environment to develop in. Blargle's way put Unix tools on top of Windows, which I find to be kind of clunky.
I learnt socket programming from this site. He has given everything in detail . Download an Vmware workstation and load up ubuntu . Understand the programs they are pretty much straight forward .
Maybe you can try to look at Network Socket on the web. You can easily find a lot of good tutorial that can answer your question.
You can use the compiler you want on your system, depending on what are you using now.

Compile C++ over FTP

I would like to know if I can use g++ to compile C++ source files stored on an FTP server? Can this be done?
Note: The FTP server is within the local network
You can't execute commands over FTP, nor can you operate directly on files stored on an FTP server unless you have mapped the FTP server to a filesystem. How to do the latter depends on your operating system.
Since you said g++, I assume Linux, so look into FTPFS.
No, this is not possible. Ftp doesn't allow you to execute programs on the server, it is just used to transfer files. To execute programs (like the compiler) you need some different kind of access to the server, like for example with Ssh.
If you are using a Linux system (and probably any *nix or BSD flavout as well) then yes it is possible if the ftp-server is mounted as a filesystem on your machine, like Tyler McHenry wrote.
It is however not neccessary to "look into FTPFS" if you are using any recent Gnome-based distro. In Ubuntu (9.04) I can do "Places"->"Connect to server" and choose FTP. Then, when the folder is opened in Nautilus you can find the mounted directory in ~/.gvfs/ and then you should be able to compile it without any trouble at all.
I would be very surprised if KDE did not have the same feature, but the directory will be mounted somewhere else.
Does the FTP server have a public website that works with scripting languages, such as PHP? If so, you could upload your source code, edit a PHP file that calls system and compile your code.
In general this probably isn't a good idea: It's a slow, manual process & could be subject to security problems if the PHP script lets you edit the compilation command.

If possible how can one embed PostgreSQL?

If it's possible, I'm interested in being able to embed a PostgreSQL database, similar to sqllite. I've read that it's not possible. I'm no database expert though, so I want to hear from you.
Essentially I want PostgreSQL without all the configuration and installation. If it's possible, tell me how.
Run postgresql in a background process.
Start a separate thread in your application that would start a postgresql server in local mode either by binding it to localhost with some random free port or by using sockets (does windows support sockets?). That should be fairly easy, something like:
system("C:\Program Files\MyApplication\pgsql\postgres.exe -D C:\Documents and Settings\User\Local Settings\MyApplication\database -h 127.0.0.1 -p 12345");
and then just connect to 127.0.0.1:12345.
When your application quits, you can always send a SIGTERM to your thread and then wait a few seconds for postgresql to quit (ie join the thread).
PS: You can also use pg_ctl to control your "embedded" database, even without threads, just do a "pg_ctl start" (with appropriate options) when starting the application and "pg_ctl stop" when quitting it.
You cannot embed it, nor should you try.
For embedding you should use sqlite as you mentioned or firebird rdbms.
Unless you do a major rewrite of code, it is not possible to run Postgres "embedded". Either run it as a separate process or use something else. SQLite is an excellent choice. But there are others. MySQL has an embedded version. See it at http://mysql.com/oem/. Also several java choices, and Mac has Core Data you can write too. Hell, you can even use FoxPro. What OS you on and what services you need from the database?
You can't embed it as a in process type thing like sqlite etc, but you can easily embed it into your application setup using Inno setup at http://www.innosetup.org. Search their mailing list archive and you will find someone did most of the work for you and all you have to to is grab the zipped distro and you can easily have postgresql installed when the user installs your app. You can then use the pg_hba.conf file to restrict the server to local host only. Not a true embedded DB, but it would work.
PostgreSQL is intended to run as a stand-alone server; it's probably possible to embed it if you hack at it hard and long enough, but it would be much easier to just run it as intended in a separate process.
HSQLDB (http://hsqldb.org/) is another db which is easily embedded. Requires Java, but is an excellent and often-used choice for Java applications.
Anyone tried on Mac OS X:
http://pagesperso-orange.fr/bruno.gaufier/xhtml/prod_postgresql.xhtml
http://www.macosxguru.net/article.php?story=20041119135924825
(Of course sqlite would be my embedded db of choice as well)
Well, I know this is a very very very old post, but if anyone has nowadays this question, I would refer to:
You can use containers running Postgres. Here's a post that could be helpful, doing something along this line using R:
https://rsangole.netlify.app/post/2021/08/07/docker-based-rstudio-postgres/?utm_source=pocket_mylist
Take a look at duckdb https://duckdb.org/docs/installation/ It is relatively new and still needs to mature. But it works pretty much like an embedded database ("In-process, serverless"), with bindings for several languages (Python, R, Java, ...)

Resources