SHARE
TWEET

Old Technique

a guest Jul 7th, 2013 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CopyFileOverwrite[f1_,
  2.   f2_] := (If[FileExistsQ[f2], DeleteFile[f2], False];
  3.   CopyFile[f1, f2];)
  4. NewRun[s_] := (str =
  5.    OpenWrite[FileNameJoin[{$TemporaryDirectory, "temp.bat"}]];
  6.   WriteString[str, s];
  7.   Import["!" <> Close[str], "Text"];)
  8.  
  9. WriteToClipboard[type_,
  10.   data_] := (CopyFileOverwrite[
  11.    FileNameJoin[{$InstallationDirectory, "SystemFiles", "Links",
  12.          "NETLink", "Wolfram.NETLink.dll"}],
  13.        FileNameJoin[{$TemporaryDirectory, "Wolfram.NETLink.dll"}]];
  14.       csfile = FileNameJoin[{$TemporaryDirectory, "File.cs"}];
  15.       exefile = FileNameJoin[{$TemporaryDirectory, "File.exe"}];
  16.   file = OpenWrite[csfile];
  17.   WriteString[file, "using System;
  18.       using Wolfram.NETLink;
  19.       using System.IO;
  20.       using System.Drawing;
  21.       using System.Windows.Forms;
  22.  
  23.       public class File{
  24.        [STAThread]
  25.        public static void Main(String[] args) {
  26.           string input = System.Console.In.ReadToEnd();
  27.           byte[] bytes = Convert.FromBase64String(input);
  28.           Stream stream = new MemoryStream(bytes);
  29.           IDataObject dataObject = new DataObject();
  30.           dataObject.SetData(args[0], stream);
  31.           Clipboard.SetDataObject(dataObject, true);
  32.         }
  33.       }"];
  34.   Close[file];
  35.   Import["!C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe \
  36.  /reference:Wolfram.NETLink.dll " <> csfile, "Text"];
  37.   dataloc = FileNameJoin[{$TemporaryDirectory, "data.txt"}];
  38.   datafile = OpenWrite[dataloc];
  39.   WriteString[datafile, data];
  40.   Close[datafile];
  41.   NewRun["type " <> dataloc <> " | " <> exefile <> " " <> type];)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top