Converting a Windows .cpp file for Unix system? - windows

I have a .cpp file that I wrote on my Windows 8 computer and I am trying to paste its code into my schools Unix based system via Putty SSH client. The editor that is used on the Unix machines is the Vi editor. When I copy all the code from my .cpp file in my Windows computer and right click on the Vi editor and paste, the code shows up but its all over place and I can't even read it(I am pretty sure it wouldn't compile either). Is there a way to fix it so the code maintains its formatting in the Vi editor ? Thanks for any help !

There is usually a unix utility called dos2unix and one called unix2dos which will convert your file to dos or unix format.
If you have those it should just be a matter of:
dos2unix myfile.cpp myfile.cpp
Also, instead of pasting it into your editor try using pscp to copy the file to your target machine.
pscp myfile myname#hostname:/mydirectory/myfile

I think you must be getting beaten by the difference in the line endings of windows and unix.
You can try using editor like Notepad++ and save the file on windows.
Open the file in Noteapd++ and Edit -> EOL Conversion -> UNIX Format and save

Related

How can I open ".scpt" files on Windows?

I would like to open a ".scpt" file, what editors can I use?
P.S. I am using Windows, so the App should support Windows.
As others have said, .scpt files are compiled versions of your script. Save your script as a .applescript (i.e. TEXT) file if you want to edit your script on a machine without AppleScript.

use Ubuntu at virtual box based on windows 7 cannot edit text

I have a problem that
1. my laptop is X86 win7 & install a virtual box.
2. Based on virtual box, I installed a Ubuntu.
Now I share a folder between win7 & Ubuntu.
And edit a bash file on windows by, ex UltraEdit.
After then, when I run the bash on Ubuntu.
It said:
mkdir: cannot create directory ‘dvbpsi\r’: Protocol error
cp: cannot stat 'src/table/.h': No such file or directory*
It seems that \r is wrong.
Instead, if I tried to store in virtual box, it shows the wrong msg below:
It seems that I CANNOT store anything from virtual OS to a shared folder.
Is there a smart way to resolve it?
Thanks in advance!!
UltraEdit can create, edit and save text files with DOS (\r\n) or UNIX (just \n) or MAC (just \r) line terminators.
The line terminator type is indicated for active file in status bar at bottom of UltraEdit main window.
The conversion between the various line terminator types can be done at any time in UltraEdit using for example the DOS to UNIX conversion command or on using Line terminator option in Save As dialog.
The default line ending type for new files can be also configured in configuration at
Advanced - Settings/Configuration - File Handling - DOS/Unix/Mac Handling.
I suggest following configuration settings for using UltraEdit mainly for editing Windows text files and only sometimes for Unix shell scripts:
Default file type for new files ... DOS
Unix/Mac file detection/conversion ... Automatically convert to DOS format
Only recognize DOS terminated lines (CR/LF) as new lines for editing ... not checked
Save file as input format (Unix/Mac/DOS) ... checked
Status bar shows original line terminator format (on disk) ... checked
So creating/editing shell scripts on Windows with UNIX type of line termination is easy using UltraEdit on Windows being also available for Linux and Mac.

PuTTY run sh can't install fileinfo extension

I have a DreamHost server, and I would like to install the fileinfo extension.
I managed to create a custom php.ini file that's cool, but I'm totally stuck at this part in their documentation:
Please make sure to run 'dos2unix fileinfo_ext.sh' from the shell if you use a Windows-based editor to create this file.
So I am on Windows and running PuTTY and I have no clue about this part.
I copied fileinfo_ext.sh to my cgi-bin directory where my custom php.ini file is, but how do I go further? I'm totally lost how to run this command.
How can I do it?
"dos2unix" is a utility used to convert file from Windows line endings (CR+LF) to Unix line endings (LF).
So if you use Notepad to edit the file it will have Windows line endings. So dos2unix should be used on your computer (for that file) before sending it by FTP (or executing it on the host if you have ssh access and they have dos2unix).
But if you already use an editor which supports converting to Unix line endings, like UltraEdit or Notepad++ then all you need is to do a "convert to Unix" before saving the file.
You run the command as explained in the message. SSH to the server and login. Then cd to the location of the file, something like cd /path/to/your/site/cgi-bin and then run dos2unix fileinfo_ext.sh.
I hope this helps.

Parsing text from a linux log on windows (Adding spaces that are removed)

So I do a little work from time to time on Linux and today I needed to document some text files copied from the terminal window. The only problem was that I brought a linux text file over to notepad on my Win7 comp, and I noticed that all the carriage returns were removed from the text.
Is there any way to quickly add the carriage returns back in?
You can do the conversion before the transfer:
unix2dos -o <pattern>
In case you need to keep the old files or you have only read access to them:
unix2dos -n <original-file> <converted-file>
You might not have this utility available by default in your linux distro in which case you will need to install the tofrodos package.
Use Notepad++ instead of Notepad. It's free and it has a lot of functionality, including proper handling of EOL marks.

When to use .exe and when not?

I dont really understand whats going on and cant see the difference:
I'm downloaded the base64.exe for creating base64 text under windows. i copied it to C:\Windows\ because its in the %PATH% variable.
Now i want to try it: echo Hello | base64 works great. Okay i dont need to append .exe and as far as i know i dont need to do it also with .bat and .com files.
But now i have some cygwin tools installed and for example tried which base64, which doesnt work, because it says that base64 is not in path. Then i typed in which base64.exe and got C:\Windows.
So my question is now: when i need to use .exe and when i dont? Is it only when i'm using cygwin tools that i need to append .exe?
Cygwin is a shell which emulates UNIX behaviour. UNIX doesn't know anything about .exe, thats why Cygwin can't find base64.exe. Under UNIX, binaries are stored without an extionsion added to their filename, e.g. just base64.
Windows CMD automatically appends .bat, .com, .exe and the like to your file names. Cygwin does not. So if you are using a linux shell you have to append it manually.
Since Cygwin is aware that it always runs under Windows it might append .exe if you want to perform certain actions in the shell itself (e.g. opening a file), to behave more friendyl to Windows users who expect this behaviour. However programs running under Cygwin might not integrate those features since they were mainly devoloped for usage under UNIX. That could be a reason why which base64 fails.

Resources